Question

I have next example of script:

The proposal is to find ID = 67109AB inside "file.txt", using an external variable, in this case, it's called: var. But, when I run script, it doesn't take value of variable like search pattern.

So, someone can help me to know if there is missing something?

Thanks for your help.

    fu="/67109AB/"
awk -v var="$fu" '
     var {
        print $0
}' file.txt
Was it helpful?

Solution

I think you're looking for something like this:

fu="67109AB"; awk -v var="$fu" '$0 ~ var' file.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top