Operating System - Linux
1753479 Members
4895 Online
108794 Solutions
New Discussion юеВ

How can i get specifically some lines between a sign ?

 
Manuales
Super Advisor

How can i get specifically some lines between a sign ?

Hi all,
i have this output file:

scheduled Jobs:
Level type Pri
==== (this is a note: first "=")
..xxxx
..xxxx
..xxxx
..xxxx
..xxxx
..xxxx
..xxxx
..xxxx
==== (this is a note: second "=")

Ended Jobs
Level type Pri
===== (this is a note: third "=")
....
...
..
...
....
===== (this is a note: fourth "=")

i want to get only the lines between the first "=" and the second "=", it means, only the scheduled Jobs --> lines: ..xxxx
How can i get them? can i do it with awk? please your support.
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: How can i get specifically some lines between a sign ?

Hi Manuales:

As you stated your requirement and the pattern of the data:

perl -ne 'if (?^===?...?^===?) {print unless /^===/}' file

Regards!

...JRF...
Bob_Vance
Esteemed Contributor

Re: How can i get specifically some lines between a sign ?

Here's an example script using 'awk' :


## cat /tmp/doit

#
awk '
BEGIN {c=0}
{
while (getline) {
if ( match($0 , "===") ) {
c=c+1
if (c>=2) { exit }
continue
}
if (c==0) {
continue
}
if (c==1) {
print $0
continue
}
}
}
END { }
'


Here's a run of it:

## cat /tmp/in | /tmp/doit
..xxxx1
..xxxx2
..xxxx3
..xxxx4
..xxxx5
..xxxx6
..xxxx7
..xxxxE


bv
"The lyf so short, the craft so long to lerne." - Chaucer
Peter Nikitka
Honored Contributor

Re: How can i get specifically some lines between a sign ?

Hi,
in my opinion it is better to keep the awk standard parsing:

awk '/^====/ {mark++}
mark>1 {exit}
mark'

mfg Peter
PS: untested
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"
Bob_Vance
Esteemed Contributor

Re: How can i get specifically some lines between a sign ?

@Peter

I've found it easier to use 'awk' in the complex way rather than trying to grok the eccentricities of it's simpler syntax.
Of course, then it just becomes another programming language.

I got used to using it before 'perl' was around.

BTW, your script prints the first "====" line , but I don't know how to fix it :>)


bv
"The lyf so short, the craft so long to lerne." - Chaucer
Dennis Handly
Acclaimed Contributor

Re: How can i get specifically some lines between a sign ?

>BV: I've found it easier to use 'awk' in the complex way rather than trying to grok the eccentricities of it's simpler syntax.

I too started that way but I learn as I go along.

>but I don't know how to fix it :>)

A "next" will cause it to go to the next cycle, think of it as a super "continue":
awk '
/^====/ {
if (++mark > 1) exit
next
}
mark { print $0 }' input-file
Peter Nikitka
Honored Contributor

Re: How can i get specifically some lines between a sign ?

OK,
other solution without the 'xxxx'-line:

awk 'mark
/^====/ {mark++}
mark>1 {exit}'
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"