I am trying to pass two variables to awk in order to replace a word (-v var1) with a space (" ") at specific line (-v var2). When I ran it, nothing is replaced at the line I wanted.
My first approach to do it is:
palabra=betina; i=5 ; awk -v var1="$i" -v var2="$palabra" 'NR==var1 {sub("var2"," ")}{print }' Countries > tmp
on the file "Countries", with content is:
usa
usa
colombia
spain
betina
Remove the quotes around var2 and you should be good.
palabra=betina; i=5 ; awk -v var1="$i" -v var2="$palabra" 'NR==var1 {sub(var2," ")}{print }' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With