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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

complex "grepping"

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
i have a text like this:

date1
>sshfdksjf
bleble
sleeping 1 seconds
date2
>khfskfjsldfds
ble
sleeping 1 seconds
sdfkjhsh
ksfhkshf
date3
>slkfdjslkjfs
sjlsfls
slkfdhslkjd
sleeping 1 seconds
skjhskjf
kjshksfd


And I need to get 1 line beore ^> and lines after ^> but before "sleeping 1 seconds" line. it would be nice to have matches delimetered by an empty line like on example below

so expected output of above sample should be:

date1
>sshfdksjf
bleble

date2
>khfskfjsldfds
ble

date3
>slkfdjslkjfs
sjlsfls
slkfdhslkjd

 
Hi,

If I understand your sample, you want just to blank the lines containing 'sleeping 1 seconds'.
Is it what you are expecting ?


 
one line befoe the match and line after the match to a line containing 'sleeping 1 seconds'

the 'sleeping 1 seconds' means that the matched proces was completed and the program is waiting for a new one.

when a new one comes, after its completion new 'sleeping 1 seconds' appears and so on.
 
Hi,

Put this code in a file say try.awk
Code:
BEGIN { line_before=$0 ; matched=0 ; firstline=1}
$0 ~ /^>/ { if (firstline==1) {firstline=0}else{ print line_before} ; matched=0
}
$0 !~ /sleeping 1 seconds/ {if ( matched==0 ) {print $0 }; line_before=$0  }
$0 ~ /sleeping 1 seconds/ {printf "\n" ;matched=1 }

execute the file
Code:
awk -f try.awk /path/to/your_file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top