If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > script/command to combine lines???

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-26-04, 15:24
rlee rlee is offline
Registered User
 
Join Date: Aug 2004
Posts: 4
script/command to combine lines???

I posted this in
dBforums > Usenet Groups > comp.unix.* > comp.unix.shell,

I figure someone might be able to help me here instead.

I need a script to combine lines. Dont know the set amount of lines, for ex, the text in the file is:

082404 23:12:59
[ Event blah1 blah 2 blah 4 ]
(path) /etc/temp
082404 23:22:60
[ Event blah1 blah 2 blah 4 ]
082404 23:32:12
[ Event blah1 blah 2 blah 4 ]
(path) /etc/temp/dff/sdf
....
....
....

and so on. I need it to look like this after the script:

082404 23:12:59 [ Event blah1 blah 2 blah 4 ] (path) /etc/temp
082404 23:22:60 [ Event blah1 blah 2 blah 4 ]
082404 23:32:12 [ Event blah1 blah 2 blah 4 ] (path) /etc/temp/dff/sdf
....
....

Basically, puts those 3 elements into 1 line, however there might not always be a path. I think I need to use the awk command? But I'm not familar with using the awk command. Thanks in advance!

this is what i tried:

the text file is temp and this is what i typed:

awk '{$line1 = $0; getline $line2; getline $line3; print $line1, " ", $line2, " ", $line3}' temp

and the output is:

082404 23:12:59 082404 23:12:59 082404 23:12:59
082404 23:22:60 082404 23:22:60 082404 23:22:60
[ Event blah1 blah 2 blah 4 ] [ Event blah1 blah 2 blah 4 ] [ Event blah1 blah 2 blah 4 ]

although it isnt exactly what i want, i just need some if statements in there, it seems like $line2 and $line3 are getting the same value as $line1, why is that? Thanks
Reply With Quote
  #2 (permalink)  
Old 08-26-04, 16:56
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
try something like this for starters:

nawk -f rlee.awk myInput.txt
Code:
FNR != 1 && $1 ~ /^[0-9][0-9]*$/ { printf("\n") }
{printf("%s ", $0)}
Reply With Quote
  #3 (permalink)  
Old 08-27-04, 09:54
rlee rlee is offline
Registered User
 
Join Date: Aug 2004
Posts: 4
^^ thanks, that worked perfectly, although i don't know how it works thanks a bunch
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On