Getting output a line after specific line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting output a line after specific line
# 1  
Old 01-14-2010
Getting output a line after specific line

Hi

I am a rookie and I would like to know how to make a script that prints as a output lines between two lines let say first variable is a :


Mon Aug 31 09:00:00 2009 CET

and the last line is

Tue Sep 08 09:00:00 2009 CET

also

lets say third line from

Mon Aug 31 09:00:00 2009 CET




thanks in advance I would realy apreciate the help
# 2  
Old 01-14-2010
Quote:
Originally Posted by DinoFly
Hi

I am a rookie and I would like to know how to make a script that prints as a output lines between two lines let say first variable is a :


Mon Aug 31 09:00:00 2009 CET

and the last line is

Tue Sep 08 09:00:00 2009 CET
try:
Code:
sed -n '/Mon Aug 31 09:00:00 2009 CET/,/Tue Sep 08 09:00:00 2009 CET/p' file

or

Code:
awk '/Mon Aug 31 09:00:00 2009 CET/,/Tue Sep 08 09:00:00 2009 CET/' file

# 3  
Old 01-15-2010
Hi and thank you for your fast response.

This works perfectly for the first part but my problem is not yet solved couse I need the solution for printing a specific line after a matched line...,

I want to thank you for quick reply with the solution.
# 4  
Old 01-15-2010
Quote:
Originally Posted by DinoFly
Hi and thank you for your fast response.

This works perfectly for the first part but my problem is not yet solved couse I need the solution for printing a specific line after a matched line...,

I want to thank you for quick reply with the solution.
Try:
Code:
awk '/pattern/{next;print;exit}' file

or:

Code:
sed -n '/pattern/{n;p;}' file


Last edited by Franklin52; 01-15-2010 at 03:42 AM.. Reason: adding sed solution
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do we display specific row of an output from bottom given line number?

I pass a number to my script. Passing "1" below. ./getfile.sh 1 echo "User entered: $1" ls -ltr *.conf | sed -n '$p' I wish to use ls -ltr i.e list files in ascending order of time the latest showing at the bottom of the output. Number 1 should get me the last row of ls -ltr output i.e... (9 Replies)
Discussion started by: mohtashims
9 Replies

2. 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

3. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

4. Shell Programming and Scripting

Commenting a specific line and inserting a new line after commented line.

Hello All, I have following file contents cat file #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd line=eeeeee #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! I would like to comment line line=eeeeee and insert a new line... (19 Replies)
Discussion started by: manishdivs
19 Replies

5. UNIX and Linux Applications

display which line returns specific output

Hi, I'm trying to figure out a way to find which line in my file.txt with IP addresses: 192.168.0.1 192.178.0.2 etc... returns specific result when I execute command affecting all lines. For example when I run: for line in `cat file.txt`; do snmpget $line done it displays the... (5 Replies)
Discussion started by: svetoslav_sj
5 Replies

6. Shell Programming and Scripting

Using awk to read a specific line and a specific field on that line.

Say the input was as follows: Brat 20 x 1000 32rf Pour 15 p 1621 05pr Dart 10 z 1111 22xx My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour" I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies

7. Shell Programming and Scripting

Counting rows line by line from a specific column using Awk

Dear UNIX community, I would like to to count characters from a specific row and have them displayed line-by-line. I have a file called testAwk2.csv which contain the following data: rabbit penguin goat giraffe emu ostrich I would like to count in the middle row individually... (4 Replies)
Discussion started by: vnayak
4 Replies

8. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies

9. Shell Programming and Scripting

Remove a specific line from grep output string

Dear All I want to search string "1000" from input file and if it found i want remove line that contain 1000 and also remove 3 line above it and 2 line below it. INPUT FILE: BHAT-D 2 aaa ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES 50 ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

10. Shell Programming and Scripting

Deleting Characters at specific position in a line if the line is certain length

I've got a file that would have lines similar to: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00... (10 Replies)
Discussion started by: Cailet
10 Replies
Login or Register to Ask a Question