The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
RegExp: From first occurrance to last (at line start) jjinno Shell Programming and Scripting 6 01-08-2008 12:04 PM
To cut end string from line visu Shell Programming and Scripting 7 12-20-2007 10:22 PM
get the NF of a string line ozzman Shell Programming and Scripting 5 02-01-2007 09:01 PM
How I Can get String From the Line habuzahra UNIX for Dummies Questions & Answers 2 10-29-2006 03:55 AM
Add string after line X alienET Shell Programming and Scripting 2 10-13-2005 06:52 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-08-2007
Registered User
 

Join Date: Nov 2006
Posts: 17
Question regexp to get first line of string

Hi everybody

Code:
for file in *
#Bash performs filename expansion
#+ on expressions that globbing recognizes.
do
	
	output="`grep -n "$1" "$file"`"
	echo "$file: `expr "$output" : '\(^.*$\)'`"

done
In the above bash script segment, I try to print just the first line of string named output.

I've got a problem with the regexp. It returns the full string which is multilined.

Thank you in advance for any help
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-08-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
You can try :
Code:
echo ""$file: `echo "$output" | sed -n 1p`"

Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 05-08-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
grep -n "$1" "$file" | read output
Reply With Quote
  #4 (permalink)  
Old 05-09-2007
Registered User
 

Join Date: Nov 2006
Posts: 17
Thank all of you
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0