I create the following awk example script in order to add the line - "line 1" after the line "target"
we set the variable var="target" , to export the value target inside the awk,
But when we run the script , seems that awk not read the value in var
The script with awk:
[root@master tmp]# more test.bash
#!/bin/bash
awk -v var="target" '1; done != 1 && /var/ {
print "line 1"
done = 1
}' file
The file:
[root@master tmp]# more file
target
When I run the script we get:
[root@master tmp]# ./test.bash
target
While expected results should be
target
line 1
I will happy to know what I am wrong with awk syntax,
And how to fix it so var inside the awk will get the value - "target"