|
|
print lines between two patterns
I have a file like
Tuesday
abcdefg
cdfjdkf
kdfkd
dfdfjj
dfkdfjd
Friday
djfkddkf
djfdjdkjf
djfkdj
...
..
Tuesday
...
..
Friday
...
..
..
what I am looking for is to print the lines between first two
partterns "Tuesday -- Friday" and then stop (exit).
the output should like
abcdefg
cdfjdkf
kdfkd
dfdfjj
dfkdfjd
what is simplest way of doing it with awk or sed or perl?
Thanks in advance.
|
|
0
|
|
|
|
Reply
|
guo
|
8/7/2003 3:39:56 PM |
|
guo@andrews.edu (Limin Guo) writes:
> I have a file like
>
> Tuesday
> abcdefg
> cdfjdkf
> kdfkd
> dfdfjj
> dfkdfjd
> Friday
> djfkddkf
> djfdjdkjf
> djfkdj
> ..
> .
> Tuesday
> ..
> .
> Friday
> ..
> .
> .
>
> what I am looking for is to print the lines between first two
> partterns "Tuesday -- Friday" and then stop (exit).
>
> the output should like
>
> abcdefg
> cdfjdkf
> kdfkd
> dfdfjj
> dfkdfjd
>
> what is simplest way of doing it with awk or sed or perl?
awk '
$0 == "Friday" && flag {
exit
}
flag {
print
}
$0 == "Tuesday" {
flag = 1
}'
--
Best regards, Aleksey Cheusov.
|
|
0
|
|
|
|
Reply
|
Aleksey
|
8/7/2003 4:22:35 PM
|
|
On 8/7/2003 10:39 AM, Limin Guo wrote:
<snip>
> what I am looking for is to print the lines between first two
> partterns "Tuesday -- Friday" and then stop (exit).
>
> the output should like
>
> abcdefg
> cdfjdkf
> kdfkd
> dfdfjj
> dfkdfjd
>
> what is simplest way of doing it with awk or sed or perl?
>
> Thanks in advance.
awk '/^Friday$/ && on == 1 {exit}
on == 1 {print}
/^Tuesday$/ {on=1}'
Regards,
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
8/7/2003 7:42:07 PM
|
|
In article <3F32AB8F.5040301@Lucent.com>,
Ed Morton <mortonAVOIDINGSPAM@Lucent.com> wrote:
>
>
>On 8/7/2003 10:39 AM, Limin Guo wrote:
><snip>
>> what I am looking for is to print the lines between first two
>> partterns "Tuesday -- Friday" and then stop (exit).
>>
>> the output should like
>>
>> abcdefg
>> cdfjdkf
>> kdfkd
>> dfdfjj
>> dfkdfjd
>>
>> what is simplest way of doing it with awk or sed or perl?
>>
>> Thanks in advance.
>
>awk '/^Friday$/ && on == 1 {exit}
> on == 1 {print}
> /^Tuesday$/ {on=1}'
#!gawk
a=/foo/,b=/bar/ {if (a || b) a--;else print}
|
|
0
|
|
|
|
Reply
|
gazelle
|
8/7/2003 8:08:51 PM
|
|
Ed Morton <mortonAVOIDINGSPAM@Lucent.com> wrote in message news:<3F32AB8F.5040301@Lucent.com>...
> On 8/7/2003 10:39 AM, Limin Guo wrote:
> <snip>
> > what I am looking for is to print the lines between first two
> > partterns "Tuesday -- Friday" and then stop (exit).
> >
> > the output should like
> >
> > abcdefg
> > cdfjdkf
> > kdfkd
> > dfdfjj
> > dfkdfjd
> >
> > what is simplest way of doing it with awk or sed or perl?
> >
> > Thanks in advance.
>
> awk '/^Friday$/ && on == 1 {exit}
> on == 1 {print}
> /^Tuesday$/ {on=1}'
>
> Regards,
>
> Ed.
Thank you all for answering my questions. here is another question:
what should I do if two patterns are same? On the other word, the
patterns are all Tuesdays and no Fridays and I need the lines between
from two "Tuesday".
|
|
0
|
|
|
|
Reply
|
guo
|
8/11/2003 1:14:05 PM
|
|
On 8/11/2003 8:14 AM, Limin Guo wrote:
> Ed Morton <mortonAVOIDINGSPAM@Lucent.com> wrote in message news:<3F32AB8F.5040301@Lucent.com>...
<snip>
>>awk '/^Friday$/ && on == 1 {exit}
>> on == 1 {print}
>> /^Tuesday$/ {on=1}'
<snip>
> Thank you all for answering my questions. here is another question:
> what should I do if two patterns are same? On the other word, the
> patterns are all Tuesdays and no Fridays and I need the lines between
> from two "Tuesday".
The above solution will still work. Just change "Friday" to "Tuesday".
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
8/11/2003 2:01:54 PM
|
|
|
5 Replies
1075 Views
(page loaded in 0.133 seconds)
Similiar Articles: print lines between two patterns - comp.lang.awkI have a file like Tuesday abcdefg cdfjdkf kdfkd dfdfjj dfkdfjd Friday djfkddkf djfdjdkjf djfkdj ... .. Tuesday ... .. Friday ... .. .. what I am looking for is to ... extracting a particular pattern from a line - comp.unix.shell ...print lines between two patterns - comp.lang.awk extracting a particular pattern from a line - comp.unix.shell ..... in each line, a pattern exists (digits and dashes ... gawk problem matching multiple patterns ?!? HOW-TO? - comp.lang ...print lines between two patterns - comp.lang.awk gawk problem matching multiple patterns ?!? HOW-TO? - comp.lang ... Join two lines in pattern matching, search, then ... Large file problems - block pattern - comp.lang.awkprint lines between two patterns - comp.lang.awk... two awk commands - comp.lang.awk... if (data[$2]++ == 0) lines[++count] = $2} END {for (i = 1; i<=count; i++) print ... Difference between grep, egrep and fgrep - comp.unix.programmer ...print lines between two patterns - comp.lang.awk Difference between grep, egrep and fgrep - comp.unix.programmer ... print lines between two patterns - comp.lang.awk ... sed: printing only between {} - comp.unix.shellprint lines between two patterns - comp.lang.awk Unix Sed Tutorial: Printing File Lines using Address and Patterns Let us review ... Chicago Newyork Battlecreek Jackson ... Supressing newline at the end of a print statement? - comp.lang ...print lines between two patterns - comp.lang.awk Supressing newline at the end of a print statement? - comp.lang ... Replace all new lines, only if... - comp.lang.awk!$0 ... Adding a line break (newline) to output - comp.lang.awkprint lines between two patterns - comp.lang.awk Adding a line break (newline) to output - comp.lang.awk print lines between two patterns - comp.lang.awk Adding a line ... Finding common lines between text files - comp.unix.programmer ...print lines between two patterns - comp.lang.awk Unix Sed Tutorial: Printing File Lines using Address and Patterns Let us ... Sed Find and Display Text Between Two Strings ... Join two lines in pattern matching, search, then assign fields to ...Is there a way in awk that I could join the two lines, search for a pattern on say field2 ... echo $LINE | awk '{print $13}'` echo Asset Tag: `echo $LINE | awk '{print $2 ... Print lines between two patterns , the awk way … « NixTipExample input file: test -3 test -2 test -1 OUTPUT top 2 bottom 1 left 0 right 0 page 66 END test 1 test 2 test 3 The standard way .. print lines between two patterns - comp.lang.awk | Computer GroupI have a file like Tuesday abcdefg cdfjdkf kdfkd dfdfjj dfkdfjd Friday djfkddkf djfdjdkjf djfkdj ... .. Tuesday ... .. Friday ... .. .. what I am looking for is to ... 7/23/2012 8:51:51 AM
|
|
|
|
|
|
|
|
|