The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-18-2009
daikeyang daikeyang is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 24
Search for string in a file and extract another string to a variable

Hi, guys. I have one question:

I need to search for a string in a file, and then extract another string from the file and assign it to a variable.

For example:

the contents of the file (group) is below:
...
ftp:x:23:
mail:x:34
...
testing:x:2001
sales:x:2002
development:x:2003
...

I want to search for string "testing", then extract group id (2001) on the same line and assign it to a variable.

Can anybody help me with me question?

Thank you very much for your time in advance

-K.D