Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8813889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:58:24+00:00 2026-06-14T03:58:24+00:00

This is my shell script that receives a string as an input from the

  • 0

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 :

  1. The 1st command line argument passed is treated as input file.
    e.g. : awk 'code' file arg1 arg2 arg3
    only file is treated as input file

  2. If 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:58:26+00:00Added an answer on June 14, 2026 at 3:58 am

    If there’s no -f option, the first non-option argument is treated as the script, and the remaining arguments are input files. If there’s a -f option, the script comes from that file, and the rest are input files.

    If and only if there are no input file arguments, it reads the input from stdin. This means if you pipe to awk and also give it filename arguments, it will ignore the pipe.

    This is the same as most Unix file-processing commands.

    Try this:

    awk -f summary.awk -v query="$query" "$input_file"
    

    This will set the awk variable query to the contents of query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a Bash shell script that does something like this: #!/bin/bash
Can someone write a PHP script that reproduces the functionality of this linux shell
For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null
What is current directory of shell script? Is this current directory from which I
I'm writing a shell script that looks like this: for i in $ACTIONS_DIR/* do
I have this shell script #!/bin/sh PATHS=( a b c d ) for PATH
This is a crude korn shell script that someone else wrote. I don't know
I have this bash shell-script command that causes date to run if make succeeds
I have a shell script background process that runs nohupped. This process shall receive
I put together this shell script to do two things: Change the delimiters in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.