Scripting - How To Use A Variable Inside An Awk Statement - Unix & Linux Stack Exchange
Scripting - How To Use A Variable Inside An Awk Statement - Unix & Linux Stack Exchange
Unix & Linux Stack Exchange is a question and answer site for
users of Linux, FreeBSD and other Un*x-like operating
systems. Join them; it only takes a minute:
Sign up
statement? [duplicate]
#!/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}}'
marked as duplicate by
steeldriver, Stéphane
Chazelas, dhag, techraf,
GAD3R Nov 29 '16 at 14:02
This question has been asked
before and already has an
answer. If those answers do not
fully address your question,
please ask a new question.
2 Answers
#!/bin/ksh
echo "Enter the matching pattern"
IFS= read -r pattern
path=/home/siva/
echo "Navigating to $path"
cd "$path" || exit
awk -v pattern="$pattern" '$0 ~ patter
This site uses cookies to deliver our services and to show you relevant ads and job listings. By using our site, you
acknowledge that you have read and understand our , , and our . Your use of
Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.