Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I can not use unix $variable in Fiexd search of awk command.

Please see below my commands.

a="NEW_TABLES NEW_INSERT"
b="NEW"
echo $a | awk -v myvar=$b -F'$0~myvar' '{print $2}'

is not returning any output

but if manually enter the $b value there , its working as below

echo $a | awk -v -F'NEW' '{print $2}'

    outputs: 
 TABLES NEW_INSERT
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
228 views
Welcome To Ask or Share your Answers For Others

1 Answer

This should make it:

$ a="NEW_TABLES NEW_INSERT"

$ echo $a | awk -F"NEW_" '{print $2}'
TABLES 

$ b="NEW_"
$ echo $a | awk -F"$b" '{print $2}'
TABLES 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...