Find the answer to your Linux question:
Results 1 to 2 of 2
I am just beginning with sed and awk and understand that they are "per" line input. That is, they operate on each line individually, and output based on rules, etc. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2005
    Posts
    2

    Sed or awk help requested parsing multiple lines


    I am just beginning with sed and awk and understand that they are "per" line input. That is, they operate on each line individually, and output based on rules, etc.

    But I have multi-line text blocks that looks as follows, and wish to ONLY extract the text between the first hyphen (-) and the ending part of that phrase even though it is on a next line and may be several sentences. Note these text blocks are among many text blocks with similar features but the distinguishing feature of these text blocks are the *[digits]Some text with a hyphen - this is what I want to extract. Maybe even another sentence, too, on another line.

    * [42]Things to do - Wash clothes, clean house, write letters, take dog for walk, watch tv, eat dinner.
    * [43]Business items - Provide instructions to clients on property locations, write listing reports, copy contracts to computer disk, call state agencies.

    My preferred end result using the above sample is:

    Wash clothes, clean house, write letters, take dog for walk, watch tv, eat dinner. Provide instructions to clients on property locations, write listing reports, copy contracts to computer disk, call state agencies.

    I could really use some help on this.

    Thanks.

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Try this:
    Code:
    awk -F "- " '{print $2}' file

Posting Permissions

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