Need help to print lines contains particular string format in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to print lines contains particular string format in a file
# 1  
Old 05-20-2009
Need help to print lines contains particular string format in a file

Hi,
I want to print the lines in a file that matches particular string format using shell scripting.
# 2  
Old 05-20-2009
you can use grep ,sed or awk
just go through the man pages
# 3  
Old 05-20-2009
Thanks for ur reply..Once string format is matched i want to print same line and next four lines in a seperate file and again i need to search for string format in a file.
Whenever string format is matched i need to print same line and next four lines in a seperate output file.
Please provid the sample script using shell scripting or PERL.
# 4  
Old 05-20-2009
Quote:
Originally Posted by sudhakaryadav
Thanks for ur reply..Once string format is matched i want to print same line and next four lines in a seperate file and again i need to search for string format in a file.
Whenever string format is matched i need to print same line and next four lines in a seperate output file.
Please provid the sample script using shell scripting or PERL.
try this
Code:
 
awk '/pattern/{print};c-->0;/pattern/{c=4}'  filename > outfile

# 5  
Old 05-20-2009
Another form of vidyadhar85 solution :
Code:
 awk '/pattern/{print;c=4;next};--c>0'  filename > outfile

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a string and print all lines upto another string

Ok I would like to do the following file test contains the following lines. between the lines ABC there may be any amount of lines up to the next ABC entry. I want to grep for the filename.txt entry and print the lines in between (and including that line) up to and including the last line... (3 Replies)
Discussion started by: revaroo
3 Replies

2. Shell Programming and Scripting

Print all lines after a string

My file has the following contents... User:SYS,O/SUser:oracle,Process:10813484,Machine:host123.xxx.xxx.xxxxxxx.com.au,Program:sqlplus@host123.xxx.xxx.xxxxxxx.com.au(TNSV1-V,LogonTime:24-JUL-2014 15:04 I would like to print all character appearing after the string LogonTime: My output... (5 Replies)
Discussion started by: Nagesh_1985
5 Replies

3. Shell Programming and Scripting

Grep for the string and then print the next 4 lines

RHEL 5.8 I have a text file like below. I want to grep for a string and then print the next 4 lines including the line with the string I grepped for For eg: I want grep for the string HANS and then print the next 4 lines including HANS $ cat someText.txt JOHN NATIONALITY:... (7 Replies)
Discussion started by: omega3
7 Replies

4. Shell Programming and Scripting

How to print the lines in a file for the given string?

Hi, I have a file with contents test id text day test sah dh dhs yeay fg jsh jsjk my need: I give a string as a input, it check the file and display the lines with the given string e.g input : test output: test id text day test sah dh dhs (1 Reply)
Discussion started by: nanthagopal
1 Replies

5. UNIX for Dummies Questions & Answers

Compare 2 files print the lines of file 2 that contain a string from file 1

Hello I am a new unix user, and I have a work related task to compare 2 files and print all of the lines in file 2 that contain a string from file 1 Note: the fields are in different columns in the files. I suspect the is a good use for awk? Thanks for your time & help File 1 123 232 W343... (6 Replies)
Discussion started by: KevinRidley
6 Replies

6. Shell Programming and Scripting

Print lines between two lines after grep for a text string

I have several very large file that are extracts from Oracle tables. These files are formatted in XML type syntax with multiple entries like: <ROW> some information more information </ROW> I want to grep for some words, then print all lines between <ROW> AND </ROW>. Can this be done with AWK?... (7 Replies)
Discussion started by: jbruce
7 Replies

7. Shell Programming and Scripting

Print #of lines after search string in a big file

I have a command which prints #lines after and before the search string in the huge file nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=0 a=10 s="STRING1" FILE The file is 5 gig big. It works great and prints 10 lines after the lines which contains search string in... (8 Replies)
Discussion started by: prash184u
8 Replies

8. Shell Programming and Scripting

print string at the end of lines in text file

hello, I go text file like this E:/DDD/Dyndede/wwww E:/DDD/sss.com/ffffg/fff E:/DDD/vvvvvv/dd E:/DDD/sss.com/bbbbbb E:/DDD/sss.com/nnnn/xxI want to print /alpha.jpg at the end of every lines like that E:/DDD/Dyndede/wwww/alpha.jpg E:/DDD/sss.com/ffffg/fff/alpha.jpg... (8 Replies)
Discussion started by: davidkhan
8 Replies

9. Shell Programming and Scripting

How to print the number of lines from a file, the starting string should be passed`

Hi , I have file, which has the below content: line 100 a b c d line300 a s d f s line200 a s d a (3 Replies)
Discussion started by: little_wonder
3 Replies

10. Shell Programming and Scripting

How to print current month - 1 in string format

I need to get the current month -1 in string format, like Feb-2006. I am using k shell. Any help is appreciated. (3 Replies)
Discussion started by: mogli4
3 Replies
Login or Register to Ask a Question