return line below string grepp'ed for


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting return line below string grepp'ed for
# 1  
Old 01-30-2007
return line below string grepp'ed for

Hi there

Does anybody know how to get grep to return the line underneath the string i am grepping for ie, if i have this file



Code:
hello 
everybody
how
are
you

and i issue #cat file | grep how

I would like it to return the line below (in this case the string "are")

Is this possible at all

cheers
Gary
# 2  
Old 01-30-2007
SED solution

Code:
sed -n "N;/how\n/s/.*\n//p" file

# 3  
Old 01-30-2007
An awk solution:

Code:
awk '/how/{getline;print}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

How to add a new string at the end of line by searching a string on the same line?

Hi, I have a file which is an extract of jil codes of all autosys jobs in our server. Sample jil code: ************************** permission:gx,wx date_conditions:yes days_of_week:all start_times:"05:00" condition: notrunning(appDev#box#ProductLoad)... (1 Reply)
Discussion started by: raghavendra
1 Replies

2. Shell Programming and Scripting

Return line when line below has the string

I have a file with data like this. I want to look for MultiLoad and pull that line and the line above. I cant use the grep -B 1 I dont have that version and cant install on the server. is there a awk or perl that will do it. "CMPGN_RPT_DEV_TT"."text1" (TableId 0029H 5CEEH) bypassed due to... (4 Replies)
Discussion started by: wambli
4 Replies

3. Shell Programming and Scripting

SH script to parse string and return multi-line file

Hello all, I have been asked to exercise my shell scripting and it has been 10 plus years since I used to do it so I can not remember hardly anything and ask for your help. What I need to do is copy a line out of a file that can be 10 to 100 characters long, I then need to parse this line into... (3 Replies)
Discussion started by: Alivadoro
3 Replies

4. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

5. Shell Programming and Scripting

How to return a string?

function blah { return "string" } it keeps saying string: not found How can i do this guys? Because I'm trying to do something like this function print_daemon_options { echo "Start Daemons - Please enter one or a combination of the following:" if isDatasubEnabled &&... (11 Replies)
Discussion started by: pyscho
11 Replies

6. UNIX for Dummies Questions & Answers

Search for string and return lines above and below

Hi, I have a file with the following contents: COMPANY ABCD TRUCKER JOE SMITH TRUCK 456 PLATE A12345678 TRUCKER BILL JONES TRUCK 789 PLATE B7894561 I need to create a script or search command that will search for this string '789' in the file. This string is unique and only... (7 Replies)
Discussion started by: doza22
7 Replies

7. Shell Programming and Scripting

Search string and return only the 5th line

I have looked at almost every posting on here regarding, grep, sed, awk, nawk, perl methods to perform this function, but they are just not returning the results I hope to see. Example File: abcdef 123456 ghijkl 7890123 7890123 7890123 7890123 mnopqrs 456789 This is the most... (4 Replies)
Discussion started by: doza22
4 Replies

8. Shell Programming and Scripting

KSH Functions String return

Hy everybody I'm trying to write a function like function(){ final=$1 return $final } but I get following error: "return: bad non-numeric arg ''" what shall I do? Isn't it possible to return strings?:confused: thanks lucae (2 Replies)
Discussion started by: lucae
2 Replies

9. Shell Programming and Scripting

return string in functions

Hi friends I need to return string value in functions can anyone help me out to return string values rather than integer. #!/bin/bash add_a_user() { USER=$1 COMPANY=$2 shift; shift; echo "Adding user $USER ..." echo "$USER working in $COMPANY ..." ret_type=YES return... (1 Reply)
Discussion started by: kittusri9
1 Replies

10. Shell Programming and Scripting

deleting 'carriage return' from string

hi there I'm getting a string from a sqlplus query, and I need to compare it with another string Problem here, is that the string i get from query brings a 'carriage return' with it, and comparing throws always false value. i need to delete all carriage retun charactres in string. how... (6 Replies)
Discussion started by: viko
6 Replies
Login or Register to Ask a Question