bash - How to rearrange text file output result -
i write unix script following have ff result:
textfile1 contains following text:
keyval1,1 keyval1,2 keyval1,3 keyval1,4 keyval2,1 keyval2,2 keyval3,1 keyval4,1 keyval4,3 keyval4,4
expected result:
keyval1 (1,2,3,4) keyval2 (1,2) keyval2 (1) keyval4 (1,3,4)
thank you.
i'm new unix , have done far. it's not working yet though :(
#!/bin/ksh f1 = 'cut -d "," -f 1 keyval.txt' f2 = 'cut -d "," -f 2 keyval.txt' while f1 <> f2 echo f1 "("f2")" done > output.txt
you can in breeze using awk:
#!/usr/bin/awk -f begin { fs = "," closebracket = "" } { if (key != $1) { key = $1 printf "%s%s (%s", closebracket, key, $2 } else { printf ",%s", $2 } closebracket = ")\n" } end { printf "%s", closebracket }
Comments
Post a Comment