Use sed to replace first 8 and last 4 pipes on every line in a file
Posted
by Dan Watling
on Stack Overflow
See other posts from Stack Overflow
or by Dan Watling
Published on 2010-02-19T17:50:56Z
Indexed on
2010/05/28
0:11 UTC
Read the original article
Hit count: 553
sed
Here's the situation, I have a text file that is pipe-delimited and one of fields contains pipe characters. I already have a sed script that will change it to be tab-delimited, but the problem is it's terribly slow. It will replace the first occurrence of a pipe 8 times, then replace the last occurrence of a pipe 4 times. I'm hoping there's a quicker way to do what I need.
Any thoughts would be appreciated. Here's my current sed script:
sed 's/|\(.*\)/\t/;s/|\(.*\)/\t/;s/|\(.*\)/\t/;s/|\(.*\)/\t/;s/|\(.*\)/\t/;s/|\(.*\)/\t/;s/|\(.*\)/\t/;s/|\(.*\)/\t/;s/|\(.*\)/\t/;s/\(.*\)|/\t/;s/\(.*\)|/\t/;s/\(.*\)|/\t/;s/\(.*\)|/\t/' $1 > $1.tab
Thanks,
-Dan
© Stack Overflow or respective owner