Newbie here. I am trying to use awk print a few information. So I wrote a shell scripts
#!/bin/bash
turbVar="U"
bcName="outlet"
str="$turbVar $bcName b.c. = "
# method-1
awk -v RS='}' '/'$bcName'/ { printf "%20s = %s\n" $str $4; exit;}' BCFile | tr -d ";"
# method-2
awk -v RS='}' -v var1=$bcName '$0 ~ var1 { printf "%20s = %s\n" $str $4; exit;}' BCFile | tr -d ";"
The BCFile
file contents are
boundary
{
inlet
{
type fixedValue;
value uniform (5 0 0);
}
outlet
{
type inletOutlet;
inletValue $internalField;
value $internalField;
}
....
}
I hope to output something like
U outlet b.c. = inletOutlet
Sadly, this does not work. it complains awk: (FILENAME=0/U FNR=4) fatal: not enough arguments to satisfy format string %20s = %s
.
Why I can't use $str variable in awk printf?
Second question, which method is better? Using '/'$bcName'/
or using -v var1=$bcName '$0 ~ var1
?, why I cant use '/$bcName/
or '/"$bcName"/
directly? What is the difference between strong quote and weak quote here?