0

I am new to bash scripting. I am trying to run the following script :

#! /bin/bash

#the following command runs fine within the bash script
awk>/home/Bash_Scripts/filename1 -F, '$3!="constant"{print}' /home/Bash_Scripts/logs.csv

# THE FOLLOWING COMMAND WORKS FINE FROM COMMAND LINE BUT NOT FROM WITHIN BASH SCRIPT

/usr/bin/awk -f /home/Bash_Scripts/process.awk /home/Bash_Scripts/filename1 

Can someone please explain why? Both are awk commands. One works only from commandline and not from within the bash script.

Thanks in advance.

5
  • 5
    not enough details: what errors do you see? Commented Jan 25, 2014 at 2:26
  • 2
    Where there's lack of information or lack of effort from the OP, there will be lack of responses. Anyone could have helped in a heartbeat if there was enough information. Commented Jan 25, 2014 at 2:42
  • 1
    Show your /home/Bash_Scripts/process.awk Commented Jan 25, 2014 at 5:11
  • Execute the commands and copy/paste your display so we can see what you're doing and what error message you're getting, if any. Commented Jan 25, 2014 at 13:27
  • A space between awk and > might help. Commented Feb 29, 2016 at 22:34

1 Answer 1

1

Three points:

  1. You are using /home/Bash_Scripts/filename1 as you output file in the script but as input file in the command line
  2. /home/Bash_Scripts/logs.csv is your input file in the script.
  3. You use /usr/bin/awk in the command line but just awk in the script. This is backwards to what is normally done as you know what PATH is set to in the command line but no idea in general for a script.
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Thanks for the reply. But it still doesnt explain why process.awk is not executed from within the script. process,awk is a simple awk program that adds values of 2 fields in the input file. This line works perfectly fine from the command line : /usr/bin/awk -f /home/Bash_Scripts/process.awk /home/Bash_Scripts/filename1 but not from within the script. There are no erros. It simply is not executed.I dont see the values printed when I run the script from within the script
Solved it. Thanks. I just used '<' operator for the inout file./usr/bin/awk -f /home/Bash_Scripts/process.awk < /home/Bash_Scripts/filename1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.