Page 1 of 1

Replace any other instance of character per line

Posted: Wed Nov 28, 2018 12:03 am
by Glenn
Been a while since I fired this up..

Could anybody remind me of the best way to replace any other instance of a character (except for the first) per line please?

Bit of background: I have a 2 column CSV file that is semicolon delimited. I would like any other instance of a semicolon APART from the first instance replacing with a space.

Thank you.

Re: Replace any other instance of character per line

Posted: Thu Dec 13, 2018 4:59 am
by dfhtextpipe
Use a PCRE pattern Restrict filter:

Code: Select all

Comment...
|  Replace all but the first semicolon on each line by a space
|
+--Perl pattern [^(.*;)(.+)$] and Send variable 2 to subfilter
   |  [X] Match case
   |  [ ] Whole words only
   |  [ ] Case sensitive replace
   |  [ ] Prompt on replace
   |  [ ] Skip prompt if identical
   |  [ ] First only
   |  [ ] Extract matches
   |      Maximum text buffer size 4096
   |  [ ] Maximum match (greedy)
   |  [ ] Allow comments
   |  [ ] '.' matches newline
   |  [X] UTF-8 Support
   |
   +--Replace [;] with [\x20]
         [X] Match case
         [ ] Whole words only
         [ ] Case sensitive replace
         [ ] Prompt on replace
         [ ] Skip prompt if identical
         [ ] First only
         [ ] Extract matches

         [ ] Process longest strings first
         [ ] Simultaneous search
         [ ] Log summary only
       
David
(a long time user of TextPipe)