replace nth occurence of string in each line of a text file
Posted
by dnkb
on Super User
See other posts from Super User
or by dnkb
Published on 2010-05-20T16:12:18Z
Indexed on
2010/05/20
16:20 UTC
Read the original article
Hit count: 202
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?
Thank you
© Super User or respective owner