×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Join 2 lines

Join 2 lines

Join 2 lines

(OP)
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


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

RE: Join 2 lines

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

$ join.awk table1.txt
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.

RE: Join 2 lines

(OP)
Thank you aigles for your response. I really appreciate all your help. Your solution works! thumbsup2

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close