[SunHELP] awk and shell scripts


Tue Feb 18 12:05:10 CST 2003


change your awk to wrap double quotes around the variable:

Test=`echo $Str | awk 'BEGIN { print index( "'$Str'" , "hires") }'`

-M


-----Original Message-----
From: Simon Jespersen [mailto:shj at pine.dk]
Sent: Monday, February 17, 2003 5:50 AM
To: Sun solaris help list
Subject: [SunHELP] awk and shell scripts


Hi!
I have a small problem using shell vars in awk statements, i have found
anwsers for that question in this email list, but none of them worked for
me.-

I have this script where i testing for string functions.

I want the awk statement to look at the Str var and return where the
occurense of the string hires starts within this string. But i can4nt get
awk to tread Str as a variable, but i know it can be done.
I would be very happy if somebody would tell me how to do this in genrally
as im using awk more and more in my scripts.

#!/bin/sh
Str="/opt/share/mosaic44/share/hires/00/00/05/34/21h.002"
Str1="/A5000/nydb/hires"

Test=`echo $Str | awk 'BEGIN { print index( '$Str' , "hires") }'`
echo $Test
Simon Jespersen
_______________________________________________
SunHELP maillist  -  SunHELP at sunhelp.org
http://www.sunhelp.org/mailman/listinfo/sunhelp


More information about the SunHELP mailing list