[SunHELP] awk and shell scripts

Simon Jespersen shj at pine.dk
Mon Feb 17 06:50:03 CST 2003


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


More information about the SunHELP mailing list