x=3 A=`echo $A|awk '{print $x}'` echo $A
does not print 3. How can I use variables with awk *
Pass variables to awk using the -v flag.
awk
-v
x=3 A=`echo $A|awk -vy=$x '{print y}'` echo $A
You can use shell variables this way: "'$your-shell-variable'" or '$your-shell-variable' . The first considers the variable as a string, and later considers it a number. Below is the code you want:
"'$your-shell-variable'"
'$your-shell-variable'
x=3 A=`echo $A|awk '{print "'$x'"}'` echo $A
What is the echo point of $A ? It just creates a useless plug and pipe.
$A
x=3 A=`awk -vy=$x 'BEGIN {print y}'` echo $A
And while I'm in it, this seems like a confusing and expensive way to write A=$x
A=$x
Source: https://habr.com/ru/post/890685/More articles:LINQ-to-SQL stored procedures - c #Big O Notation to match algo strings - c ++is std :: vector faster than a simple array? - c ++svn_load_dirs.pl - why download it? final official place? - svnasp.net single sign not working - asp.netHow can I get PixelFormat BitmapSource - c #FindDivisions [] does not work as directed - wolfram-mathematicaHow to select all previously deleted texts after recovery - vimHow to use UglifyJS from Ant build? - javascriptiTextSharp Creates Corrupted PDF File - c #All Articles