sidnow
1
Hi all,
I want to output the following pattern in a comma separted format, but am not able to do it.
Table1.FIND.Value= 124
Data
Data
Data
Data
Data
Table1.FIND.Value =256
Data
Data
Data
Data
Data
The outPut i expect is
Table1.FIND.Value=124,Data,Data,Data,Data,Data
Table1.FIND.Value=256,Data,Data,Data,Data,Data
I am able to do all in one go with
awk 'BEGIN{RS="\n";ORS=",";}{print $0}' File
But this outputs everything as one single record with comma separated values.
Not sure how to achieve this.
TrY:
awk '/FIND\.Value/{if(s)print s; gsub(FS,x); s=$1; next}{s=s "," $1} END{if(s)print s}' file
1 Like
Hello sidnow,
Could you please try following and let me know if this helps.
awk '{gsub(/= | =/,"=",$0);} /^Table1/ && A{print A;A=$0;next} {;A=A?A OFS $0:$0} END{print A}' OFS=, Input_file
Output will be as follows.
Table1.FIND.Value=124,Data,Data,Data,Data,Data
Table1.FIND.Value=256,Data,Data,Data,Data,Data
Thanks,
R. Singh
1 Like
Another one
awk '{printf (/FIND\.Value/ ? rs : ",") "%s", $0; rs=RS} END {printf rs}' file
1 Like
sidnow
5
Worked like a charm
---------- Post updated at 02:49 PM ---------- Previous update was at 02:49 PM ----------
This one too.Worked like a charm
---------- Post updated at 02:49 PM ---------- Previous update was at 02:49 PM ----------
Another one, Worked like a charm
RudiC
6
If its always the same number of data:
paste -sd",,,,,\n" file
Table1.FIND.Value= 124,Data,Data,Data,Data,Data
Table1.FIND.Value =256,Data,Data,Data,Data,Data