Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Posts
    19

    Unanswered: Concatenate lines with sed?

    I am trying this to concatenate lines in a file with this command:

    sed -ne '/|$/N/s/\\\n//p' test1.txt > test2.txt

    but its not working.

    I want to concatenate all lines that end with | between a "start_here" string and an "end_here" string.

    So my file is like this:

    "start_here"|
    ldfjlsdffj|
    93849340|
    9034093|
    "end_here"|
    "start_here"|
    ldfjlsdffj|
    93849340|
    9034093|
    "end_here"|

    ...and it keeps repeating. But I want to concatenate everything between "start_here" and "end_here" to merge only the lines between and continue this throughout the file.

    Any suggestions please?

    Thanks a lot

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    what is the desired output given this sample input?
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  3. #3
    Join Date
    Feb 2005
    Posts
    19
    First I want to have:

    "start_here"|ldfjlsdffj|93849340|9034093|"end_here "|
    "start_here"|ldfjlsdffj|93849340|9034093|"end_here "|

    Then I want to remove the "start_here" and "end_here" statements:

    ldfjlsdffj|93849340|9034093|
    ldfjlsdffj|93849340|9034093|

    I guess I could probably do that in one step - this sed stuff is kind of new to me... Hopefully I'll catch on soon...

  4. #4
    Join Date
    Aug 2004
    Location
    Rome, Italy
    Posts
    81
    Hi old_farmer.
    Just use this command line in awk:

    awk '{if ($NF=="end_here|") printf "\n"; else if ($NF=="start_here|") printf ""; else printf $0}' test1.txt > test2.txt

    You'll have the result you want.

    bye bye,
    ducasio

Posting Permissions

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