Hi Experts,
I have a requirement to convert rows into columns.
For e.g.
Input File:
Output File should be like
Appreciate if you could suggest code snippet(may be awk) for above requirement...
Thanks in Advance for your help...
Hi Experts,
I have a requirement to convert rows into columns.
For e.g.
Input File:
Output File should be like
Appreciate if you could suggest code snippet(may be awk) for above requirement...
Thanks in Advance for your help...
Try
awk -F "|" '{A[$1]=A[$1]?A[$1]"|"$NF:$1"|"$NF;next}END{for(i in A) {print A}}' file
Please post in proper sub forum next time this question is not about OS
Pamu seems to be not working...END missing
awk -F "|" '{A[$1]=A[$1]?A[$1]"|"$NF:$1"|"$NF;next}END{for(i in A) {print A}}' file
if your file is sorted try this
$ awk 'NR!=1 && p!=$1{print s;s=""}{s = s ? s OFS $NF : $1 OFS $NF;p=$1}END{print s}' FS="|" OFS="|" file
abcd|125|266
defg|250|450|560
Try also
awk '{T[$1]} $1 in T {T[$1]=T[$1] "|" $NF} END {for (i in T) print i T}' 'FS=|' file
abcd|125|266
defg|250|450|560