Concat

Hi All,

My Input file contains:
Input.txt

Name|Marks
ABC|10
GHI|10
JKL|20
MNO|20
PQR|30

Output.txt

MARKS|NAME
10|ABC,GHI
20|JKL,MNO
30|PQR

Thanks in advance

  1. Use a descriptive subject text so that people know what this is about
  2. Give us more information on what you want to do, and where you're stuck. Without that you're basically asking us to do your work for free, which won't happen
  3. Start using [CODE] tags when posting code samples, console output, ...

A sketch. Add the first line, remove a space and change to commas if you want by yourself.

awk -F'|' '
NR!=1 {a[$2] = a[$2] " " $1} 
END   { for (mark in a) print mark "|" a[mark] }
' INPUTFILE
1 Like

Or..

awk 'BEGIN{OFS=FS="|";print "MARKS|NAME"} NR>1{a[$2]=a[$2] $1","}END{for(i in a)print i, substr(a,1,length(a)-1)}' inputfile

Thanks all working fine