1

I have the following huge random data

1231286234|453|1234|xxx|aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv
1231286234|453|1234|xxx| aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv
1231286234|453|1234|xxx |aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv
1231286234|453|1234|xxx | aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv

the lines are huge and data is random, i want them to be like

1231286234|453|1234|xxx aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv
1231286234|453|1234|xxx aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv    
1231286234|453|1234|xxx aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv
1231286234|453|1234|xxx aabbc|xcvxcvxcv|xcvxcvxcv|Xcvxcvxcv

2 Answers 2

0

This works for the sample you have provided.

Find what: (\w*\|\w*\|\w*\|\w*)([\|\s]*)([\w\|]*)
Replace with: \1 \3

Search mode: Regular expression

Example

6
  • Actually, there are more than 900 lines. and i just noticed after replacing the first 4th occurrence of | it does not do it in next line, instead it does it in same line.
    – regexusr
    May 20, 2015 at 7:50
  • Then you have more than 7 |-symbols on each line? May 20, 2015 at 8:07
  • yes 9 | symbols. But i only want to replace the 4th occurrence from each line. after replacing the 4th it should replace the next 4th from the second line and so on.
    – regexusr
    May 20, 2015 at 8:17
  • Then you're sample data is incorrect :-) May 20, 2015 at 8:47
  • I have updated my answer so it works with 9 |-symbols. You can use this for "Find what": (\w*\|\w*\|\w*\|\w*)([\|\s]*)(\w*\|\w*\|\w*\|\w*|\w*\|\w*) May 20, 2015 at 8:48
0
  • Ctrl+H
  • Find what: ^(?:[^|]+\|){3}.*?\K\h*\|\h*
  • Replace with: <-- a space
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

^               # beginning of line
  (?:           # start non capture group
    [^|]+       # 1 or more non pipe
    \|          # a pipe, have to be escaped as it's special character for regex
  ){3}          # end group, must appear 3 times
  .*?           # 0 or more any character but new line, not greeedy
  \K            # forget all we have seen until this position
  \h*           # 0 or more horizontal spaces
  \|            # a pipe, have to be escaped as it's special character for regex
  \h*           # 0 or more horizontal spaces

Screen capture (before):

enter image description here

Screen capture (after):

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .