Find patterns and filter the text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find patterns and filter the text
# 1  
Old 06-10-2013
Sun Find patterns and filter the text

I need to filter the text in between two patterns and output that to a different file. Please help me how to do it.
Ex:
.............
<some random text>
.............
Pattern_1
<Few lines that need to be output to different file>
Pattern_2
................
...............
<more text in the file>
..............

I want to be able to Find Pattern_1, then output the next few lines until I find Pattern_2. Let me know if my request is clear or needs detailed explanation.
# 2  
Old 06-10-2013
Try:
Code:
awk '/Pattern_1/,/Pattern_2/' file

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 06-10-2013
Here is how to get lines between "Pattern_1" and "Pattern_2" with ex...
Code:
ex -s +'/Pattern_1/+1,/Pattern_2/-1 p | q!' file

This User Gave Thanks to shamrock For This Post:
# 4  
Old 06-10-2013
To include the tags (i.e. Pattern_1 and Pattern_2 in the output), bartus11's solution will work for sure...
But if you do not want the tags, you could try:

nawk '/Pattern_2/{ flag=0 } flag; /Pattern_1/{ flag=1 }' input
This User Gave Thanks to juzz4fun For This Post:
# 5  
Old 06-10-2013
thanks guys...i got what i wanted....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

2. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

3. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

4. Shell Programming and Scripting

Need to extract text repetitively between two patterns

Hi All, I want to extract the text between some pattern which occurs repeatedly in a file. For example my input is like, /home/..... ..........java:25: cannot find symbol ............ /home/...... /home/....... I want to display... (2 Replies)
Discussion started by: Vignesh58
2 Replies

5. Shell Programming and Scripting

Replacing text between two patterns

I would like to replace ], with ]]], between /* SECTION2-BEGIN */ and /* SECTION2-END */ in my file. My file contains the following information: /* SECTION1-BEGIN */ , /* SECTION1-END */ /* SECTION2-BEGIN */ , /* SECTION2-END */ /*... (5 Replies)
Discussion started by: azdps
5 Replies

6. Shell Programming and Scripting

Filter text after keyword

I've got a little problem to solve and can't find a way to solve it. If have text line like the following: keyword1: text1 keyword2: text2 keyword3: text3 Now I need a script or command, which gives me the text for the corresponding keyword. The text can consist of only one or more words.... (5 Replies)
Discussion started by: frankbullitt78
5 Replies

7. Shell Programming and Scripting

To find 3 patterns in a file

hy i have a requirement in which my script needs to find 3 patterns in a file and if any pattern is missing it should sent a mail Patterns Interval60min_Daily_readings$a.txt Interval_Daily_readings$a.txt Daily_readings$a.txt Basically i want to test for the above Patterns in the... (2 Replies)
Discussion started by: ali560045
2 Replies

8. UNIX for Dummies Questions & Answers

Copying Text between two unique text patterns

Dear Colleagues: I have .rtf files of a collection of newspaper articles. Each newspaper article starts with a variation of the phrase "Document * of 20" and is separated from the next article with the character string "===================" I would like to be able to take the text composing... (3 Replies)
Discussion started by: spindoctor
3 Replies

9. Shell Programming and Scripting

Filter some text

Dear experts, Below i have mentioned two alarms with MAJOR severity, i am intrested only with alarm contains text tre , actually i want to filter out alarm which is highlighted in bold text in some other file for further processing. I need all above three line of the alarm containing text tre... (3 Replies)
Discussion started by: Danish Shakil
3 Replies

10. Windows & DOS: Issues & Discussions

Filter data from text file

Hi All We have got a text file, which has data dumped from 60 tables. From these 60 tables of data we need data from 4 tables only. I tried assigning line numbers to filter out data, but it is not working as intended. below is the sample file ----Table1----- 3,dfs,43,df 4,sd,5,edd... (18 Replies)
Discussion started by: b_sri
18 Replies
Login or Register to Ask a Question