Pint 2nd line after particular pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pint 2nd line after particular pattern
# 1  
Old 05-27-2013
Pint 2nd line after particular pattern

Hi All
I want to make script to find out row value after particular pattern from file
Sample Input file.Here pattern is ABCD

Code:
38403040
010459
20130527
173659
39703015
ABCD
15933998
38403040
000042
20130527
173659
39703015
ABCD
15934006
38403041

Output file will be like

Code:
38403040
38403041

output will be having 2row below pattern ABCD.
Can any one help ?
# 2  
Old 05-27-2013
Code:
awk '/ABCD/ { getline ; getline ; print }' inputfile

# 3  
Old 05-27-2013
A few examples I've used:
Code:
# Print the line immediately before 'string', but not the line containing the 'string'.
sed -n '/string/{g;1!p;};h'

# Print the line immediately after 'string', but not the line containing the 'string'.
sed -n '/string/{n;p;}'

# Print one line before and after 'string', also print the line matching 'string' and its line number.
sed -n -e '/string/{=;x;1!p;g;$!N;p;D;}' -e h

# 4  
Old 05-27-2013
Another awk approach:
Code:
awk '/ABCD/{c=NR}c&&(NR-c)==2' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

3. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

4. Shell Programming and Scripting

Insert new pattern in newline after the nth occurrence of a line pattern - Bash in Ubuntu 12.04

Hi, I am getting crazy after days on looking at it: Bash in Ubuntu 12.04.1 I want to do this: pattern="system /path1/file1 file1" new_pattern=" data /path2/file2 file2" file to edit: data.db - I need to search in the file data.db for the nth occurrence of pattern - pattern must... (14 Replies)
Discussion started by: Phil3759
14 Replies

5. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

6. Shell Programming and Scripting

Print the 2nd line everytime after defined pattern is found.

Hi, I have a text file similar to the example below and I want to print the second line every time after the "--------------------------" pattern is found. The pattern is a fixed length of - characters. Example of input; 1 -------------------------- 2 3 39184018234 4 ... (10 Replies)
Discussion started by: lewk
10 Replies

7. Shell Programming and Scripting

1. search 2nd pattern after a pattern and summarize stats

I have two questions. I am sure one of the Guru will be able to help either one or both. 1. Find 2nd occurance of pattern= "Bind variable after pattern="ABN USER Admin" ...... ABN USER Admin <--- I know this string ..... Bind variable ... .. Bind variable <-- Want to print this... (4 Replies)
Discussion started by: ran123
4 Replies

8. Shell Programming and Scripting

find pattern, delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: FRM CHK 0000 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (4 Replies)
Discussion started by: nickg
4 Replies

9. UNIX for Dummies Questions & Answers

find pattern delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: W/D FRM CHK 00 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (1 Reply)
Discussion started by: nickg
1 Replies

10. Linux

pint file

to all friends i have a file abc.dat created in vim how i can print this text to lpt1: i am using fc2 printer hp1300 parallel(auto configured) i neet to pring my document from cui to lpt1: pls give me command to print abc.dat to lpt1: sadique (1 Reply)
Discussion started by: sadiquep
1 Replies
Login or Register to Ask a Question