0

So I've been working on an assignment pertaining to awk. Everything is pretty much done, except when I throw commands into a bash script (run eleven of them all automagically) I don't get any output. Am I missing some sort of syntax that awk needs to work in a script? Thanks!

I'll just give you the first four to give you an idea:

#!/bin/sh
##VARIABLES
W=/usr/share/dict/words
C=cars_file
P=/etc/passwd


##PROBLEM EXAMPLE
#display problem number
#display command
#run command
#echo whitespace


##PROBLEMS
 echo ">PROBLEM 01"
 echo    "awk '/zzan/ {print}' $W | head"          #contains 'zzan'
          awk '/zzan/ {print}' $W | head           #pipe to head
 echo

 echo ">PROBLEM 02"
 echo    "awk '/^[aeiou].*[ou]rch$/ {print}' $W | head"       #start w/lowercase vowel
 echo     awk '/^[aeiou].*[ou]rch$/ {print}' $W | head        #end in orch/urch
 echo                                                         #pipe to head

 echo ">PROBLEM 03"
 echo    "awk '/chevy/ {print}' $C"                 #display all records
 echo     awk '/chevy/ {print}' $C                  #of all chevys
 echo

 echo ">PROBLEM 04"
 echo    "awk '$1 ~ /o/ {print}' $C"               #display all records
 echo     awk '$1 ~ /o/ {print}' $C                #contains 'o' in column 1
 echo

`

1 Answer 1

2

The first awk entry should work fine (assuming your awk script does what you want. The other three have an erroneous leading echo and as such are just echoing the command instead of running it.

Sign up to request clarification or add additional context in comments.

2 Comments

Oh god. I should've seen that. The first one does, indeed, run fine. Thanks for catching my mistake!
@user3010203 don't forget accepting the answer, if it solved your problem.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.