How to find if a substring is in a variable in awk

I use awk and you need to find if the variable, in this case $ 24 contains the word 3: 2-, if so, to print the line (for the sed command) - the variable can contain more letters or spaces or \ n ..... .. eg,

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

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

Can you help me with the team please?

+3
source share
2 answers

If you are looking for "3: 2" inside $ 24, then you want $24 ~ /3:2/orindex($24, "3:2") > 0

Why are you using awk to generate a sed script?

Refresh

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}'
+4
source
awk '$24~/3:2/' file_name

this will be fixed for “3: 2” in field 24

+1
source

All Articles