15
4
I have large text files with space delimited strings (2-5). The strings can contain "'" or "-". I'd like to replace say the second space with a pipe.
What's the best way to go?
Using sed I was thinking of this:
sed -r 's/(^[a-z'-]+ [a-z'-]+\b) /\1|/' filename.txt
Any other/better/simpler ideas?
2From the
sed
info file: "Note: the POSIX standard does not specify what should happen when you mix theg' and NUMBER modifiers, and currently there is no widely agreed upon meaning across
sed' implementations. For GNU `sed', the interaction is defined to be: ignore matches before the NUMBERth, and then match and replace all matches from the NUMBERth on." – Paused until further notice. – 2010-05-20T17:29:16.450Info files... I hate them. Anyway, I removed the ambiguous part. Good comment, +1. – mrucci – 2010-05-20T20:52:58.127
1Thanks, mrucci and Dennis. I thought that there must be something simple out there. – dnkb – 2010-05-22T15:58:54.760
It seems every problem I have with text manipulation, I manage to solve with
sed
. I'm not sure I should be thanking you for makingsed
even more useful to me, but I will anyway. ;) – Jamie – 2012-04-25T15:39:25.737