1843857 Members
2561 Online
110225 Solutions
New Discussion

awk or something else

 
SOLVED
Go to solution
Igor Sovin
Super Advisor

Re: awk or something else

Thanks guys!
Now I see that all solutions work.
And one more question.
How can I get only SessionID of EP2 as output?
Hein van den Heuvel
Honored Contributor

Re: awk or something else

Hmm, doesn't Sandman's solution do just that?

Slightly differently written:

#awk '/^Ses/{l=$0} /^Bac.*: EP2/{print l; print}' x.tmp
SessionID : 2006/09/16-2
Backup Specification: EP2
SessionID : 2006/09/17-2
Backup Specification: EP2

Insert "\n" in print lines as needed.
Using perl it looks much the same:

#perl -ne '$l = $_ if /^Ses/; print $l,$_ if /^Bac.*: EP2/' x.tmp
SessionID : 2006/09/16-2
Backup Specification: EP2
SessionID : 2006/09/17-2
Backup Specification: EP2

Both solution remember any line starting with Ses..
Then they print the last one remembered, and the current line if the current line starts with Bac... and has EP2 in it.

Cheers,
Hein.
Igor Sovin
Super Advisor

Re: awk or something else

Yes it does , but I need only:
2006/09/16-2
2006/09/17-2

as output.
Hein van den Heuvel
Honored Contributor

Re: awk or something else



awk '/^Ses/{x=$3} /^Bac.*EP2/{print x}' infile


Peter Nikitka
Honored Contributor

Re: awk or something else

Hi,

if you need to extract information for a specific session only:

omnidb -session -user root -last 3 -type backup -detail |
awk -v myid=EP2 '$1 == "SessionID" {id=$NF}
/Backup Specification/ {if (id==myid) print id,$NF}'

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Sandman!
Honored Contributor

Re: awk or something else

>Yes it does , but I need only:
>2006/09/16-2
>2006/09/17-2

>as output.

slight modification to the awk command will give you just that:

# awk '{if($0~"EP2") print l; l=$NF}' infile

~cheers