Hi All
I've a file which is similar to the one given below
column1 coulmn2 column3 column4
A B C D
X Y
F G H
I would like to get it in this format
A|B|C|D
||X|Y
F||G|H
Is this possible using sed or gawk?
gawk 'NF==4{t=gensub(/[^ ]+( +).*/,"\\1",1,$0)}{gsub(t,"|");gsub(/ +/,"|")}1'
Assuming the white space is a tab ...
$ tr "\t" "|" < file
column1|coulmn2|column3|column4
A|B|C|D
||X|Y
F||G|H
Thanks a lot fpmurphy and yinyuemi.
I got it working by using sed itself.
I was not able to use gawk since i'm running it on Windows, it gave me error
gawk: cmd. line:1: 'NF==4{t=gensub(/[
gawk: cmd. line:1: ^ Invalid char ''' in expression (i think it is because windows don't like ')
tr is not working because the file is having multiple spaces (not tabs, i was thinking it was tab).
Thank you very much for your inputs.