jxh461
1
Can some one tell me how I can insert a "|" (pipe) at the 15th column throughout a file?
examples:
to insert at begining of line i use :g/^/s//\|/
to insert at ene of line i use :g/$/s//\|/
how can i insert at the 15th column position.
Thanks in advance
Vishnu
2
try sed with "tagged regular expressions", like this...
sed -e 's/^\(..............\).\(.*\)$/\1\|\2/g' yourfile > newfile
I just tagged the first 14 columns using
^\(..............\)
and from 16th column to last using
\(.*\)$
in between these two I left a single character belonging to the 15th column untagged...
in the replacement string, I reproduced the two tagged portions with a pipe in the middle using...
\1\|\2
in the above code I was replacing the 15th column with a "|", if you want to insert a pipe in the 15th column...
sed -e 's/^\(...............\)\(.*\)$/\1\|\2/g' yourfile > newfile
Cheers!
Vishnu.
1 Like