retain white spaces in fields when using awk -
i using nawk on pipe delimited file print fields index , key of fields contain white space, when there no white space space works normal, in case of white spaces somehow awk treats field separator , prints o/p new line. se input below :
input
a|b|c d e|1|2|3 a|b c|d|1|2|2 3 output index=a|b|c key=1|2|3 index=d key= index=e key= index=a|b key=1|2|2 index=c|d key=3 expected output
index=a|b|c d e key=1|2|3 index=a|b c|d key=1|2|2 3 in short 2 record 2 index , 2 keys , keep basic white spaces is.
without posting code hard tell messing up. following code produces expected output
#!/usr/bin/awk -f begin { fs=ofs="|"; } { print "index=" $1, $2, $3; print "key =" $4, $5, $6; } when fed sample input
a|b|c d e|1|2|3 a|b c|d|1|2|2 3 the output is
index=a|b|c d e key =1|2|3 index=a|b c|d key =1|2|2 3 which seem require. works because change input field separator (fs in gawk) , output field separator (ofs) pipe symbol, , print first 3 fields index , last 3 key.
Comments
Post a Comment