Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Posts
    4

    Unanswered: 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

  2. #2
    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)}

  3. #3
    Join Date
    Aug 2004
    Posts
    4
    ^^ thanks, that worked perfectly, although i don't know how it works thanks a bunch

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •