hi everybody,
i want to know how can i do to access to the value of a variable in awk request. I explain for example:
a=2
echo "hello" |awk -F "." 'BEGIN {ORS ="\n"} { print $"$a"}'
of course it dosn t work, but how can i access to the 10th value ?
if someone has any idea, please help me.
Thank you in advance.
Generally Awk does not use the '$' when accessing variable contents. It does however use the '$' for acessing field position values and special built-in variables such as NR, NF, etc. Also, to use shell variables in an Awk program you must pass them to Awk as they are not directly available. Use the -v switch to do so. $0 represents the line (record). By the way, your field separator value does not make sense for your progam as there is only 1 field and it is not delimited by anything.
hi,
if i understand i can t use an exterior variable in a awk query?
if i wan to use the second parameter of my shell script ($2) in my awk query, is it possible?
for example i want to use the length of the second parameter:
echo $2| awk '{print length($1)}' | ...
i want to use the length to read the character in that position
code
'
echo "az" | awk '{print length($1)}'
and
echo "h.ello" | awk -F "." ' {print $( the value of the previuos query )}'
how can i execute the two queries in a 1 awk query?