krk
April 8, 2013, 3:35am
1
hi,
i got files delimited by |^ character. eg.
apple|^ball|^cat|^dog|^egg
i need to find if the above file contains | (pipe ) character inside the data.eg.
apple|^ball|^cat|^d|og|^egg
.
above file contains | character in the dog data. how can i search that.
RudiC
April 8, 2013, 3:49am
2
Please use code tags as required by forum rules!
For your above question, try
$ grep -o "[^|^]\+[|][^^|]\+" file
d|og
Hi RudiC ,
Could you please explain reg ex ?
Thanks
Pravin
RudiC
April 9, 2013, 12:54am
4
[^|^]\+ one or more occurrences of any char not being ^ nor |.
[|] exactly |; in square brackets so it's not interpreted as a regex OR.
[^^|]\+ same as above
To only detect if there are pipe symbols in the data this should suffice:
grep -E '\|([^^]|$)'
--
@RudiC : if a pipe symbol is the last character on the line it is also part of the data