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

Selecting a line from a text ? 1

Status
Not open for further replies.

haux

Programmer
Apr 11, 2001
79
DZ
Hello,

I want to select a line from a paragraph , here is an example :

---BEGIN---
...
...
...

Instance Name: instance-1
Id...........: 85619156-734b-45d0-b40e-e15014902862
Job Name.....: job-1
Submitted....: 8/30/07 4:22 PM
Last Modified: 8/30/07 4:40 PM
State........: COMPLETED

Instance Name: instance-10
Id...........: a8e74565-d1d6-494d-977f-f68a0467ba41
Job Name.....: job-1
Submitted....: 8/30/07 6:56 PM
Last Modified: 8/30/07 7:02 PM
State........: PAUSED/NORMAL

...
...
...
---END---

I want to select the line "Job Name" from the paragraph containing the word "PAUSED/NORMAL"

In my case, I should get the world "job-1",

I don't know how to write a script doing such think.

Any help is welcome.

Regards.
 
Greate thank you, the awk works well !!

But I get error with sed script :

root@SERVER1:/home_user/user>#sed -n '/^Job Name/{s/.*: //;h};/PAUSED\/NORMAL/{g;p}' /input/file
sed: Function /^Job Name/{s/.*: //;h};/PAUSED\/NORMAL/{g;p} cannot be parsed.
 
Hi

haux said:
I get error with sed script
Feherke said:
Tested with GNU [tt]sed[/tt].
Well, your [tt]sed[/tt] implementation is certainly not GNU [tt]sed[/tt]. GNU [tt]sed[/tt] has improved features. And older [tt]sed[/tt] versions may have problem even with the semicolon ( ; ).

Feherke.
 
A legacy (ie standard unix ...) sed version:
Code:
sed -n -e '/^Job Name/{s/.*: //;h;}' -e '/PAUSED\/NORMAL/{g;p;}' /input/file

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top