No. The "$1" above is intended to be a reference to awk's field #1, not parameter #1 to the shell. In double quotes, the shell will expand it before awk sees it. It could be done with:
but it is generally much better to use:
as Scrutinizer suggested in message #2 in this thread.
Of course the expansion ${!var} only works with recent versions of bash. That expansion is not in the standards and (as far as I know) is not supported by any other shell. (Recent versions of the Korn shell can do something similar with reference variables, but the syntax is different.) Shell array variables aren't in the standards yet either, but indexed arrays are mostly portable between bash and ksh scripts.
This User Gave Thanks to Don Cragun For This Post:
for the command below, it looks for the 3rd field value matching "P" and printing it.
awk '{if ($3 == "P") print}' file
how would i express this if i use a loop to find more that 1 variable fro a list? this doesn't seem to work...
cat list | while read n
do
awk '{if ($3 == "$n") print}'... (1 Reply)
Hello,
i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem.
my var1 is a string constructed like this:
filename1 filerev1 filepath1
my var2 is another string constructed like this:
filename2 filerev2 filepath2
when i do... (2 Replies)
Hi,
I am facing a strange problem. I have a script that used the following to search and replace text:
sed 's/'"${find_var_parm}"'/'"${find_var_filter}"'/g' $ParmFile > $TempFile
The values of $find_var_parm and $find_var_filter are set based on search criteria. The above seems to be working... (2 Replies)
Hi,
I have a variable to be substituted in awk. I am using AIX 5.3. Here is my piece of code:
REPL_DT=`date +'%Y\\\\\\\\\/%m\\\\\\\\\/%d'`
NEW_LINE=$(echo $Line | awk '{sub ($4, '$REPL_DT'); printf "# %-7s %9s %18s\n", $2,$3,$4}')
sed $n" s/.*/$NEW_LINE/" kfile > tmp
mv tmp kfile
Here,... (2 Replies)
For example I have variable like below
echo $OUTPUT
/some/path/`uname -n`
when I try to use the variable OUTPUT like below
cd $OUTPUT or cd ${OUTPUT}
I am getting bad substituion error message
$ cd $OUTPUT
ksh: cd: bad substitution
$ cd ${OUTPUT}
ksh: cd: bad substitution
... (1 Reply)
HI,
This is the code I am using:
awk -v aaa="connect" 'BEGIN {IGNORECASE} /aaa/,/!/ {print NR}' bb
This does not throw any error but it does not work. Pls help
Thanks. (4 Replies)
Hi All,
I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command.
The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
HI
i was studying about variable substitution. below are info which was given in a online tutorial.
${parameter:-word}---> If parameter is null or unset, word is substituted for parameter.
The value of parameter does not change.
${parameter:=word}---> If parameter is null or... (3 Replies)
Hi,
input:
AAA|1
my script (the function is just an example):
gawk 'BEGIN{FS=OFS="|"}
function repeat(str, n, rep, i){
for(i=1; i<=n; i++)
rep=rep str
return rep
}
{
variable_1=repeat($1,$2)
variable_2=repeat($1,$2+1)
variable_3=repeat($1,$2+3)
... (5 Replies)