Vavad
August 5, 2011, 11:18am
1
Hi All,
I have a file example.csv which looks like this
GrpID,TargetID,Signal,Avg_Num
CSCH74_1_1,2007,61,256
CSCH74_1_1,212007,647,679
CSCH74_1_1,12007,3,32
CSCH74_1_1,207,299,777
I want the output as
GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num
CSCH74_1_1,2007,61,256
CSCH74_1_1,212007,647,679
CSCH74_1_1,12007,3,32
CSCH74_1_1,207,299,777
That is to say, the Signal header becomes Signal-CSCH74_1_1 using the 1st column entry.
Please help me urgently!!
Thanks
Try:
awk -F, -vOFS="," 'NR==1{x=$0;next}NR==2{t=$0;c=$1;$0=x;$3=$3"-"c;$0=$0"\n"t}1' file
Vavad
August 5, 2011, 12:02pm
3
Hi thanks a ton!..
could you explain me from the part NR==2? Pardon my knowledge.
Also, i have to do this with another 240 files where every file has a separate unique GrpID. Could you help me as to how can I use this for many such files?
Thank you again!
Assuming your 240 files are in the current directory:
for i in *; do awk -F, -vOFS="," 'NR==1{x=$0;next}NR==2{t=$0;c=$1;$0=x;$3=$3"-"c;$0=$0"\n"t}1' $i > $i.tmp; mv $i.tmp $i; done
Vavad
August 5, 2011, 12:35pm
5
Thank you thank you thank you.. you are so helpful!!.. I really appreciate your help!