Do you want something like this?
function get_column
{
awk -v val=$1 '{print $val}' list.txt
}
Above is returning the column match with $1
passing to the function. if you really need print the line match with line number in $1
from function, instead use below.
function get_row
{
awk -v val=$1 'NR==val{print ; exit}' list.txt
}
Or let shell evaluated and set the val
value and print that within awk
as following:
function get_column
{
awk '{print $val}' val=$1 list.txt
}
function get_row
{
awk 'NR==val{print ; exit}' val=$1 list.txt
}
Here you are passing val
with only numbers and if val
was contain backslash escape character you will encounter a problem which awk
does C escape sequence processing on values passed via -v val=
and a shell variable with val="\\n"
will change to value with \n
by awk.