script question
hello i want to search the startposition of some text but i have some problem with inserting the variable into the awk statement
the textlijn variable is filled with some text textlijn=`head -n $file_length2 pics.txt | tail -n 1` startpos=`expr awk 'BEGIN { print index("'$textlijn'", "changeModelePic") }' + 0 ` here is something fishy but what=====^^^^^^^^ thanx in advance greeting bert |
fishy? did you trying learning awk in the first place? you need to explicitly pass variables into a an awk script:
Code:
awk -v awkxyx=$xyz 'BEGIN awkxyz++ etc...' |
acid_kewpie i am just starting
can you give me more information on the code you provided or point me in the right way ( example) thx for replying |
The "-v" option to awk has to come before the actual awk program. It lets you associate a variable name with a given value inside the program. For example:
Code:
$ awk -v magic="xyzzy" 'BEGIN {print magic}' * Incidently, the reason your technique will not work is because the awk program itself is the part of the command line in single quotes. Single quotes on the command line turn off the meanings of most special characters like $. You cannot expand variables in single quotes. You can also use ENVIRON inside an awk program: Code:
awk 'BEGIN {print ENVIRON["HOME"]}' * |
carl.waldbieser thx
thats realy clear explaind the rest i will find out myself thx Bert btw here is the solution ( if someone need it in the future) startpos=`awk -v magic="$textlijn" 'BEGIN { print index(magic, "changeModelePic") }'` |
Re: script question
Quote:
Code:
startpos=`expr awk "BEGIN { print index(\"$textlijn\", \"changeModelePic\") }" + 0 ` |
All times are GMT -5. The time now is 09:51 AM. |