linux - Awk: Cannot concatenate strings -
i'm dealing awk, , have 3 variables work with:
- $0 variable - example it's equivalent to:
path/filename.cpp log_err << "error in log" << e.what();
- $logname variable - parsed out name of cpp file, namely:
filename
- $2 variable - contains default second value:
log_err
question:
what i'm trying concatenate values so:
logname=$logname $2;
but instead of expected value filenamelog_err
, this:
filename log_err << "error in log" << e.what();
what doing wrong?
edit: awk code requested:
awk '{ logname=sub(/^.*\//,"",$1); logname=sub(/\..*:/,"",$logname); print $logname; print $2; logname=$logname $2; print $logname; }' $file
edit2: fixed. never call on $ variables in awk unless it's field number. :)
awk '{ logname=$1; sub(/^.*\//,"",logname); sub(/\..*:/,"",logname); print logname; logname=logname $2; print logname; }' $file
logname=$logname $2;
this code wrong.
you used $logname
, means column index logname
, not want.
if value of logname
string filename
, awk try column $filename
here, if variable not defined/assigned, , try number, awk 0
. can test this:
kent$ echo "xxxx y y"|awk '{print $foo}' xxxx y y
so guess, fix be: (if logname
set right value, said)
logname=logname $2;
edit
you should never call $logname
check example:
kent$echo "111 222"|awk -v logname="filename" '{logname=logname $2;print logname}' filename222
Comments
Post a Comment