I have a script like this
#!/bin/ksh
echo "Enter the matching pattern"
read pattern
path= /home/siva/
echo "Navigating to $path"
cd $path
cat filename|awk '/$pattern/ {for (i=1; i<=10; i++) {getline;print}}'
i am not able to get the entered $pattern
when i execute the script.
awk -v pattern=$pattern '/$pattern/ {for (i=1; i<=10; i++) {getline;print}}'
? please try to edit your code so it's readable – Dani_l Nov 29 '16 at 13:06$pattern
. Instead, you have to say$0 ~ pattern
. In general, you cannot use variables within/ /
because awk does not have a way to distinguish them from literal text. – fedorqui Nov 29 '16 at 13:08