Sed - Printing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed - Printing
# 1  
Old 04-14-2010
Sed - Printing

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
# 2  
Old 04-14-2010
While thinking of something better..

Code:
$ sed -n "/bbb/q; /aaa/,/bbb/p" file1

aaa
1
2
3
4
5

# 3  
Old 04-14-2010
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
# 4  
Old 04-14-2010
MySQL

1-)
Code:
[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 Smilie
Code:
[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
Code:
[root@sistem1lnx ~]# sed -n '/a4_aa/,/a4_*/{;/a4\_\*/!p;}' 12
a4_aa
1
2
3
4
5

Regards

Last edited by ygemici; 04-14-2010 at 06:57 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Non printing option in sed is behaving oddly

Hi I'm having a problem with a sed command that I thought I was using correctly but apparently that's not the case. I was hoping someone here could point out what it is I am doing wrong? I am using the print, no print option for a matched pattern in sed. Everything seemed to be working fine... (2 Replies)
Discussion started by: harveyclayton
2 Replies

2. UNIX for Beginners Questions & Answers

Non printing option in sed is behaving oddly

Hi I'm having a problem with a sed command that I thought I was using correctly but apparently that's not the case. I was hoping someone here could point out what it is I am doing wrong? I am using the print, no print option for a matched pattern in sed. Everything seemed to be working fine... (5 Replies)
Discussion started by: Paul Walker
5 Replies

3. Shell Programming and Scripting

Printing the output of sed using a loop

So I am writing a bash script that will search a file line by line for unix timestamps, store all of the timestamps into an array, then check how many of those timestamps were created within the last hour, and finally increment a counter every time it finds a timestamp created within the last hour.... (6 Replies)
Discussion started by: jsikarin
6 Replies

4. Shell Programming and Scripting

Grep or sed - printing line only with exact match

Hello. In my script, some command return : q | kernel-default | package | 3.19.0-1.1.g8a7d5f9 | x86_64 | openSUSE-13.2-Kernel_stable_standard | kernel-default | package | 3.19.0-1.1.g8a7d5f9 | i586 | openSUSE-13.2-Kernel_stable_standard | kernel-default ... (3 Replies)
Discussion started by: jcdole
3 Replies

5. Shell Programming and Scripting

Searching and printing the only pattern using awk,sed or perl

Hi All, i have an output of command vmstat as below : $ vmstat System configuration: lcpu=4 mem=5376MB ent=1.00 kthr memory page faults cpu ----- ----------- ------------------------ ------------ ----------------------- r b avm fre re pi... (10 Replies)
Discussion started by: omkar.jadhav
10 Replies

6. UNIX for Dummies Questions & Answers

Printing a particular column using SED

Hi, i want to display only the particular column using SED command. For example, ps -ef|grep ash |sed -n '1p'|cut -d ' ' -f2   this gives 29067 ps -ef|grep ash |sed -n '1p'|awk '{print $2}'    this also gives the same  in the same way i need the solution using sed. Please... (4 Replies)
Discussion started by: pandeesh
4 Replies

7. Shell Programming and Scripting

sed selective printing

Hi, I have an xml file having serveral smiliar lines as below <INPUT VAR1 ="" DATATYPE ="number(p,s)" VAR2 ="" VAR3 ="3" VAR4="0" VAR5 ="ELEMITEM" VAR6 ="NO" VAR7 ="NOT A KEY" VAR8 ="17" LEVEL ="0" NAME ="UNIX" NULLABLE ="NOTNULL" OCCURS ="0" OFFSET ="19" PHYSICALLENGTH ="15"... (3 Replies)
Discussion started by: dips_ag
3 Replies

8. Shell Programming and Scripting

sed not printing lines before a regular expression.

Hey, I found a way to print the lines which is just before a regular expression, not including the expression. sed -n '/regexp/{n;p;}' myfile Now I'm looking for a way to print all lines, exept the regular expression and also the line before the same regular expression. Use code tags. (1 Reply)
Discussion started by: Livio
1 Replies

9. Shell Programming and Scripting

SED printing just parts of lines that match an expression

Hi - I am guessing this is fairly simple for someone .. but I can not quite figure it out. I need a sed command to print just parts of lines from a file. e.g. filea.txt 4710451 : Success : MODIFY : cn=user1,dc=org,dc=uk Message log started Message log ended 4710452 : Success : MODIFY :... (7 Replies)
Discussion started by: sniper57
7 Replies

10. UNIX for Dummies Questions & Answers

sed not printing variable

I have the following string stored in a variable from a file sbCvgXfsuupllsucpp11-aWa I want to use sed to search for the string in a second file: FileSys.dat sed -n "${obid}" FileSys.dat I'm getting "sed: command garbled: sbCvgXfsuupllsucpp11-aWa" The syntax seems fine...anyone... (2 Replies)
Discussion started by: orahi001
2 Replies
Login or Register to Ask a Question