INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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.

Jobs

search from Keyword to line not starting with white space

search from Keyword to line not starting with white space

search from Keyword to line not starting with white space

(OP)
Hi,

thought this is not going to be that hard but for me it obviously is.

I would like to parse some output and create a list from the lines following a hit of my search pattern.
The number of interesting lines which follow is variable but all start with two consecutive blanks.

CODE -->

pattern: some other foo bar
  interestring1: and other foo bar
  interestring2: and other foo bar
pattern2: some other foo bar
  interestring1: and other foo bar
  interestring2: and other foo bar
  interestring3: and other foo bar 

What I want is a list of
pattern interestring1 interestring2
pattern2 interestring1 interestring2 interestring3

I tried with

CODE

for pattern in `cmd` ; do cmd2 | awk -F: '/'"$pattern"'/,!/^ / { print $1 }' | xargs ; done 

and in desperation attempted

CODE

for pattern in `cmd` ; do cmd2 | awk -F: '/'"$pattern"'/,$1 !~ "^ " { print $1 }' | xargs ; done 
without success.

Thanks for help. Solution does not necessarily have to be awk btw.

RE: search from Keyword to line not starting with white space

Hi

I am afraid, this can not be solved with range pattern.

Try to use something like this :

CODE

for pattern in `cmd` ; do cmd2 | awk -F: '!/^ / { need = 0 } /'"$pattern"'/ { need = 1 } need { print $1 }' | xargs ; done 

Feherke.
feherke.ga

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!

Resources

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