Print pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print pattern
# 1  
Old 07-08-2010
Print pattern

Hi all!

I have a large file and want to print 4 pattern + 2 lines after each of the pattern

after each pattern, the lines are not the same

sed to print a pattern

Code:
sed -n '/pattern1/{N;N;N;p;}'


pattern1
.........
........
pattern2
..........
.........
pattern3
..........
.........
pattern4
..........
.........



Thanks

Last edited by Novice-; 07-08-2010 at 11:23 AM..
# 2  
Old 07-08-2010
what is your desired output?
This User Gave Thanks to ygemici For This Post:
# 3  
Old 07-08-2010
Hi,

do you mean something like this:

Code:
sed -n '/^\(pattern1\|pattern2\|pattern3\|pattern4\)/{N;N;p}' file

HTH Chris
This User Gave Thanks to Christoph Spohr For This Post:
# 4  
Old 07-08-2010
Quote:
Originally Posted by Christoph Spohr
Hi,

do you mean something like this:

Code:
sed -n '/^\(pattern1\|pattern2\|pattern3\|pattern4\)/{N;N;p}' file

HTH Chris

Yes, but not working, fichier out goes blank

---------- Post updated at 07:41 PM ---------- Previous update was at 07:31 PM ----------

Quote:
Originally Posted by ygemici
what is your desired output?
in the order of the file, for example

pattern1
.........
........
pattern2
..........
.........
pattern3
..........
.........
pattern4
..........

pattern1
.........
........
pattern2
..........
.........
pattern3
..........
.........
pattern4
..........

pattern1
.........
........
pattern2
..........
.........
pattern3
..........
.........
pattern4
..........
# 5  
Old 07-08-2010
this will be output file ok Smilie
at now can you write a little portion for your input file ?
This User Gave Thanks to ygemici For This Post:
# 6  
Old 07-08-2010
Quote:
Originally Posted by ygemici
this will be output file ok Smilie
at now can you write a little portion for your input file ?


Code:
PATTERN1
ppppapapappappapa
qmqkkqhqgqgqgqg
qmllllkkjjjj
q,nnysuydskdfopmpfp
uuuuuuuuuuuuu
gggggggggggg
dddddddd
PATTERN2:b:
FFFFD   KKKKJ
MMMMMQQQQQQM

KKKDD

PATTERN3
MMMDDD
DDDDDDD
DDDDDDDDDD
DDDDDDDDDDD
DDDDDDDDDDD
DDDDDDDDDDD
DDDDDDDDDDD
DDDDDDDDDDDDD
D
D
PATTERN4
RRRRRRRRR
FFFFF
GGGGGG

RREEEB

PATTERN1
RRRRR
RRRR
RRRRRRR
RRRRRR
PATTERN2 
FFFFFFF
FFFFF
PATTERN3
YYYY
TTTT
RR
EEE
FF
PATTERN4
RRR
ooooo
.......
............
ffffffffffffffffff
PATTERN1

Until the end of file

Moderator's Comments:
Mod Comment Code tags, please...

Last edited by Scott; 07-08-2010 at 04:13 PM..
# 7  
Old 07-08-2010
Code:
# sed -n -e :x -e '/PATTERN.*/{;N;N;p;d;}' -e tx infile
PATTERN1
ppppapapappappapa
qmqkkqhqgqgqgqg
PATTERN2
FFFFD KKKKJ
MMMMMQQQQQQM
PATTERN3
MMMDDD
DDDDDDD
PATTERN4
RRRRRRRRR
FFFFF
PATTERN1
RRRRR
RRRR
PATTERN2
FFFFFFF
FFFFF
PATTERN3
YYYY
TTTT
PATTERN4
RRR
ooooo

This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

2. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

3. Shell Programming and Scripting

Print only next pattern in a line after a pattern match

I have 2013-06-11 23:55:14 1Umexd-0004cm-IG <= user@domain.com I need sed/awk operation on this, so that it should print the very next pattern only after the the pattern mach <= ie only print user@domain.com (7 Replies)
Discussion started by: anil510
7 Replies

4. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

5. Shell Programming and Scripting

Script to match a pattern and print only the pattern and after that

Hi, I am writing a shell script to parse some files, and gather data. The data in the files is displayed as below. .......xyz: abz: ...... .......xyz: abz: ..... I have tried using awk and cut, bu the position of these values keep changing, so I can use awk and split it into columns. ... (14 Replies)
Discussion started by: Serena
14 Replies

6. Shell Programming and Scripting

Script to compare pattern and print a different pattern in each line

Hi, I am writing a shell script to parse some files, and gather data. The data in the files is displayed as below. .......xyz: abz: ......qrt: .... .......xyz: abz: ......qrt: ... I have tried using awk and cut, but the position of these values keep changing, so I wasn't able to get... (2 Replies)
Discussion started by: Serena
2 Replies

7. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

8. Shell Programming and Scripting

print lines up to pattern excluding pattern

11 22 33 44 55 66 77 When pattern 55 is met, print upto it, so output is 11 22 33 44 (1 Reply)
Discussion started by: anilcliff
1 Replies

9. Shell Programming and Scripting

Print a pattern between the xml tags based on a search pattern

Hi all, I am trying to extract the values ( text between the xml tags) based on the Order Number. here is the sample input <?xml version="1.0" encoding="UTF-8"?> <NJCustomer> <Header> <MessageIdentifier>Y504173382</MessageIdentifier> ... (13 Replies)
Discussion started by: oky
13 Replies

10. Shell Programming and Scripting

Use to awk to match pattern, and print the pattern

Hi, I know how to use awk to search some expressions like five consecutive numbers, , this is easy. However, how do I make awk print the pattern that is been matched? For example: input: usa,canada99292,japan222,france59664,egypt223 output:99292,59664 (6 Replies)
Discussion started by: grossgermany
6 Replies
Login or Register to Ask a Question