Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search from Keyword to line not starting with white space

Status
Not open for further replies.

greentea01

IS-IT--Management
Sep 17, 2015
1
DE
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top