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?
0/Usuppose to be?http://stackoverflow.com/questions/15825150/how-to-find-the-multiline-pattern-match-they-must-be-first-time-matchUis in a folder called0. :)What is the difference between strong quote and weak quote. What do you consider a "strong" vs 'weak" quote? We normally just talk about single and double quotes. In the case of your script just don't do any of the alternatives referred to in your question - they are both very bad.