Combining 2 lines in a file into 1 line

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.

sed 'N;s/\n/,/' file

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

Hi.

% paste -d, - - < infile
TABLE_NAME: ABC.TABLE1,Total = 59084806
TABLE_NAME: DEF.TABLE1,Total = 13170198

Best wishes ... cheers, drl

Thank to you all. I tried the perl solution that worked great. Not tried awk and sed solution.