bash, (g)awk, local variables

franz.reitinger franz.reitinger at htl-wels.at
Sat Jun 30 13:03:05 UTC 2012


Hi,
I'm using awk for string manipulations within a (backup)bash script. 
Among others I have to do some kind of substring operations using the 
built-in index-function:

Docu:
index(in, find)
This searches the string in for the first occurrence of the string 
find, and returns the position in characters where that occurrence 
begins in the string in. For example:

awk 'BEGIN { print index("peanut", "an") }'

Of course this example works; however I want to replace both literals 
with the content of local bash / environment variables like:

a= $(cat ANY_FILE);
b="anyString"

awk 'BEGIN { print index($a, $b) }'

Where I'm wrong & how can I use bash variables within built-in 
functions of awk?

ThanX
/franzR
/* 
 ************************************************************
 * Mail checked by Avira virus scanner (mail.htl-wels.at).
 ************************************************************
*/

 




More information about the ubuntu-users mailing list