MKNENI
March 23, 2012, 8:30pm
1
Hi all,
I have a file with lot of lines with repeating pattern. ( TABLE_NAME line followed by Total line).
I would like combine these two lines into one line seperated by cama and create a new file. Is there a simple way to do this.
Current Format ( just a sample 4 lines )
TABLE_NAME: ABC.TABLE1
Total = 59084806
TABLE_NAME: DEF.TABLE1
Total = 13170198
Desired foramat
TABLE_NAME: ABC.TABLE1,Total = 59084806
TABLE_NAME: DEF.TABLE1,Total = 13170198
Thanks in advance
mkneni
perl -pe '(/TABLE/) && (s/\n$/,/)' inputfile
Use perl -i -pe ....
for in-place editing of file.
you can use awk somthing like:
awk '/^TABLE/{gsub(\n,\,,$0}' inputfile
.
i have not tested this in shell.
ctsgnb
March 24, 2012, 7:28am
5
awk '{getline x;print $0","x}' infile
Could you please explain how it works?
Thanks
awk '/TABLE/ && getline $2' FS="\n" OFS=, infile
awk '/TABLE/{printf "%s,",$0;next}1' infile
awk 'ORS=/TABLE/?",":RS' infile
# awk '/TABLE/{printf "%s",$0}{getline;printf "%c%s\n",",",$0}' file
TABLE_NAME: ABC.TABLE1,Total = 59084806
TABLE_NAME: DEF.TABLE1,Total = 13170198
# awk '{a=$0;getline;a=a","$0;print a}' file
TABLE_NAME: ABC.TABLE1,Total = 59084806
TABLE_NAME: DEF.TABLE1,Total = 13170198
drl
March 24, 2012, 9:55am
9
Hi.
% paste -d, - - < infile
TABLE_NAME: ABC.TABLE1,Total = 59084806
TABLE_NAME: DEF.TABLE1,Total = 13170198
Best wishes ... cheers, drl
MKNENI
March 25, 2012, 8:04am
10
Thank to you all. I tried the perl solution that worked great. Not tried awk and sed solution.