This is my shell script that receives a string as an input from the user from the stdin.
#!bin/sh
printf "Enter your query\n"
read query
cmd=`echo $query | cut -f 1 -d " "`
input_file=`echo $query | cut -f 2 -d " "`
printf $input_file
if [ $input_file = "" ]
then
printf "No input file specified\n"
exit
fi
if [ $cmd = "summary" ]
then
awk -f summary.awk $input_file $query
fi
Lets say he enters
summary a.txt /o foo.txt
Now cmd
variable will take the value summary
and input_file
will take a.txt
.
Isn't that right?
I want summary.awk to work on $input_file
, based on what is present in $query
.
My understanding is as follows :
The 1st command line argument passed is treated as input file. e.g. :
awk 'code' file arg1 arg2 arg3
onlyfile
is treated as input fileIf the input file is piped, it doesn't see any of the arguments as input files. e.g. :
cat file | awk 'code' arg1 arg2 arg3
arg1
is NOT treated as input file.
Am I right?
The problem is
I get awk: cannot open summary (No such file or directory)
Why is it trying to open summary
?
It is the next word after $input_file
.
How do I fix this issue?