Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nawk : Matching dollar sign 1

Status
Not open for further replies.

IMAUser

Technical User
May 28, 2003
121
CH
i='$MY_TEST/my_file_name.dat '
echo $i
FILE_DIR=`echo $i | nawk '{print toupper(substr ( $1,match($1,"$")+1, match($1,"/" )))}'`
echo "FILE DIR $FILE_DIR "


Thats the script and what I want to do is match the occurance of the dollar sign. But it dosent match and there is no error message as well.
So I want the programme to return the string $MY_TEST

I tried to escape the dollar sign with a backslash (\) but didnt work.
Any help appreciated.
Thanks
 
echo '$MY_TEST/my_file_name.dat' | nawk 'match($0, "\\$[^/][^/]*") { print substr($0, RSTART, RLENGTH)}'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vlad,

I tried that as it is, but didnt see any output. Maybe it will help if you can tell me what the match is trying to do with the expression &quot;\\$[^/][^/]*&quot;

Thanks
 
Yet another way:
Code:
FILE_DIR=`echo $i | sed -n -e 's!.*\(\$[^/]*\).*!\1!p'`

Hope This Help
PH.
 
strange.. works with your sample from the original post.

&quot;\\$[^/][^/]*&quot;

Dollar followed by anything BUT a '/' repeated 1 or more times.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top