Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join 2 lines 1

Status
Not open for further replies.

zanzemaj

Programmer
Nov 2, 2006
35
0
0
NZ
I have a textfile named table1.txt and I want to write the records in one line. If the next line do not have any date before the line or there is a blank, this line should be paste on the first line. I would appreciate any help in solving this problem. I tried to do this, but not working
Code:
tr -s " " table1.txt > notab.txt
Code:
06/15/2007 02:28:47  TABLE "nmmp_" -  18,015,000 BYTES, 342,712 ROWS
                     ARCHIVED FOR THIS STREAM
06/15/2007 02:28:47
06/15/2007 02:28:47  STREAM TOTALS:
06/15/2007 02:28:47  TABLE "dsd_zation" -   8,711,188,670 BYTES,
                     150,192,895 ROWS ARCHIVED TOTAL
06/15/2007 02:28:47  TABLE "lu_upc" - 317,632,067 BYTES,   1,200,084 ROWS
                     ARCHIVED TOTAL
06/15/2007 02:28:47  TABLE "lu_upc_usa" - 229,112,147 BYTES, 865,803 ROWS
                     ARCHIVED TOTAL
06/15/2007 02:28:22  TABLE "dsd_zation" -   4,355,943,498 BYTES,
                     75,102,461 ROWS ARCHIVED FOR THIS STREAM
06/15/2007 02:28:35  TABLE "lu_xxx" - 158,866,056 BYTES, 600,190 ROWS ARCHIVED
                     FOR THIS STREAM
I need the records to be written this way:
Code:
[small]
06/15/2007 02:28:47  TABLE "nmmp_" -  18,015,000 BYTES, 342,712 ROWS ARCHIVED FOR THIS STREAM
06/15/2007 02:28:47  
06/15/2007 02:28:47  STREAM TOTALS:
06/15/2007 02:28:47  TABLE "dsd_zation" -   8,711,188,670 BYTES, 150,192,895 ROWS ARCHIVED TOTAL
06/15/2007 02:28:47  TABLE "lu_upc" - 317,632,067 BYTES,   1,200,084 ROWS ARCHIVED TOTAL
06/15/2007 02:28:47  TABLE "lu_upc_usa" - 229,112,147 BYTES, 865,803 ROWS ARCHIVED TOTAL
06/15/2007 02:28:47  TABLE "dsd_zation" -   4,355,943,498 BYTES, 75,102,461 ROWS ARCHIVED FOR THIS STREAM
06/15/2007 02:28:47  TABLE "lu_xxx" - 158,866,056 BYTES, 600,190 ROWS ARCHIVED FOR THIS STREAM
[/small]
 
An awk solution :
Code:
#!/usr/bin/awk -f
# Awk program : join.awk

/^[0-9][0-9]\// { if (line) print line; line=""}
                { gsub(/[[:space:]]+/, " "); line = line $0 }
END             { if (line) print line }
Output:
Code:
$ [COLOR=blue]join.awk table1.txt[/color]
06/15/2007 02:28:47 TABLE "nmmp_" - 18,015,000 BYTES, 342,712 ROWS ARCHIVED FOR THIS STREAM
06/15/2007 02:28:47
06/15/2007 02:28:47 STREAM TOTALS:
06/15/2007 02:28:47 TABLE "dsd_zation" - 8,711,188,670 BYTES, 150,192,895 ROWS ARCHIVED TOTAL
06/15/2007 02:28:47 TABLE "lu_upc" - 317,632,067 BYTES, 1,200,084 ROWS ARCHIVED TOTAL
06/15/2007 02:28:47 TABLE "lu_upc_usa" - 229,112,147 BYTES, 865,803 ROWS ARCHIVED TOTAL
06/15/2007 02:28:22 TABLE "dsd_zation" - 4,355,943,498 BYTES, 75,102,461 ROWS ARCHIVED FOR THIS STREAM
06/15/2007 02:28:35 TABLE "lu_xxx" - 158,866,056 BYTES, 600,190 ROWS ARCHIVED FOR THIS STREAM
$


Jean-Pierre.
 
Thank you aigles for your response. I really appreciate all your help. Your solution works! [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top