The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk -help needed rider29 Shell Programming and Scripting 6 05-30-2008 03:02 PM
rpm needed maooah Linux 0 01-08-2008 04:58 AM
Scp Help Needed !!!! scooter17 UNIX for Dummies Questions & Answers 3 09-20-2006 09:50 AM
Cut help needed!!!!!! scooter17 UNIX for Dummies Questions & Answers 1 08-15-2006 07:41 AM
Help is needed abcde Shell Programming and Scripting 3 12-30-2005 12:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-18-2008
Registered User
 

Join Date: Sep 2008
Posts: 2
help needed on awk

Hi

i have a file /services which has the following content.

ff1 2201
f1 2202

In my program following logic is used.

SVC=$NICKNAME
PRT=$(awk '/'$SVC'/ { print substr($2,1,index($2,"/")-1); }'/services)

where SVC will be ff1 and f1.

when SVC is f1 the output of the second line will be 2201 and 2202.

How should I modify the second line such that it will look for the exact string and output only 2201 for ff1 and only 2202 for f1?

Thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 09-18-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
The /regex/ looks for "regex" anywhere on the line. Use ^ to explicitly require the match to occur at beginning of line.

Code:
awk /^"$SVC"/' { ... }'
Reply With Quote
  #3  
Old 09-18-2008
Registered User
 

Join Date: Sep 2008
Posts: 2
Thanks a lot

PRT=$(awk '/'^"$SVC"'/ { print substr($2,1,index($2,"/")-1); }' /etc/inet/services)

is perfectly working fine... :-)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:39 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 Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0