Register
It is currently Sun Apr 20, 2014 6:13 am

Search text string.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Wed Aug 26, 2009 9:35 am   

Joined: Thu Aug 06, 2009 10:45 am
Posts: 4
Hi,

I need a script which works like this:

I give it an input string, and it searches for the string within a text file, and if it finds it it outputs the line on which it found the string, up to the first space.

So if I typed
Code:
script orange
and the text file had a line saying
Code:
blue purple orange
it would return
Code:
blue
.

Thanks.


Top
 Profile  
 PostPosted: Thu Aug 27, 2009 2:19 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 224
Location: London - UK
Code:
awk '/mysearchstring/ { print $1 }' textfile


I'll leave it as a test for you to turn it into a script :)


Top
 Profile  
 PostPosted: Sat Aug 29, 2009 3:34 pm   

Joined: Thu Aug 06, 2009 10:45 am
Posts: 4
Thanks that helped me.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP