![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
The /regex/ looks for "regex" anywhere on the line. Use ^ to explicitly require the match to occur at beginning of line.
Code:
awk /^"$SVC"/' { ... }'
|
|
#3
|
|||
|
|||
|
Thanks a lot
PRT=$(awk '/'^"$SVC"'/ { print substr($2,1,index($2,"/")-1); }' /etc/inet/services) is perfectly working fine... :-) |
|||
| Google The UNIX and Linux Forums |