Hi,
I need to print the lines between 2 pattern.
Eg
aaa
1
2
3
4
5
bbb
Required Output
aaa
1
2
3
4
5
I tried sed -n '/aaa/,/bbb/p' , but it prints the bbb also.
Thank you,
Sreedevi
Hi,
I need to print the lines between 2 pattern.
Eg
aaa
1
2
3
4
5
bbb
Required Output
aaa
1
2
3
4
5
I tried sed -n '/aaa/,/bbb/p' , but it prints the bbb also.
Thank you,
Sreedevi
While thinking of something better..
$ sed -n "/bbb/q; /aaa/,/bbb/p" file1
aaa
1
2
3
4
5
Thanks Scott!
It works perfectly fine.
Let me make my question generic
a4_*
a
s
f
a4_aa
1
2
3
4
5
a4_*
6
7
8
a4_*
9
10
a4_cc
11
12
(1)I need to print between a4_aa and the next a4_*
(2) what happens if my a4_aa is the last one and after that it does not see the a4_* paatern
Thanks,
Sreedevi
1-)
[root@sistem1lnx ~]# cat 12
a4_aa
1
2
3
4
5
a4_*
6
7
8
a4_*
[root@sistem1lnx ~]# sed -n '/a4_aa/,/a4_*/p' 12
a4_aa
1
2
3
4
5
a4_*
2-)if the a4_aa last line the output is only contains "a4_aa" line
[root@sistem1lnx ~]# cat 12
a4_*
6
7
8
a4_*
a4_aa
[root@sistem1lnx ~]# sed -n '/a4_aa/,/a4_*/p' 12
a4_aa
#Last Line and doesnt exist "a4_*" in next lines
or
[root@sistem1lnx ~]# sed -n '/a4_aa/,/a4_*/{;/a4\_\*/!p;}' 12
a4_aa
1
2
3
4
5
Regards