开发者

How to find if substring is in a variable in awk

i am using awk and need to find if a variable , in this case开发者_如何学运维 $24 contains the word 3:2- if so to print the line (for sed command)- the variable may include more letters or spaces or \n....... for ex.

$24 == "3:2" {print "s/(inter = ).*/\\1\"" "3:2_pulldown" "\"/" >> NR  }

in my above line- it never find such a string although it exists.

can you help me with the command please??


If you're looking for "3:2" within $24, then you want $24 ~ /3:2/ or index($24, "3:2") > 0

Why are you using awk to generate a sed script?

Update

To pass a variable from the shell to awk, use the -v option:

val="3:2"  # or however you determine this value
awk -v v="$val" '$24 ~ v {print}'


awk '$24~/3:2/' file_name

this will serach for "3:2" in field 24

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜