Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have been developing Windows Software for years. I am trying to branch out and learn Linux. It will really help with my new job.

I have picked up the book, "Awk and Sed" 2nd Edition. I am running Ubuntu 13.04; working with the terminal window. I am working through the book and have run into an example that I cannot get to work.

I have been trying everything that I can find to get this to work. If I type the example with out using the second script file, it works as expected. However when I try to work as instructed in the book (i.e., using a script file), I get the following: "byState: command not found". The command that fails is:

sed -f nameState list | byState

What is my problem?

Here is a set of data: List =

John Daggett, 341 King Road, Plymouth MA
Alice Ford, 22 East Broadway, Richmond VA
Orville Thomas, 11345 Oak Bridge Road, Tulsa OK
Terry Kalkas, 402 Lans Road, Beaver Falls PA
Eric Adams, 20 Post Road, Sudbury MA
Hubert Sims, 328A Brook Road, Roanoke VA
Amy Wilde, 334 Bayshore Pkwy, Mountain View CA
Sal Carpenter, 73 6th Street, Boston MA

The first script is: nameState =

s/ CA/, California/
s/ MA/, Massachusetts/
s/ OK/, Oklahoma/
s/ PA/, Pennsylvania/
s/ VA/, Virginia/

The second script is: byState =

#! /bin/sh
awk -F, '{ 
    print $4 ", " $0 
    }' $* | 
sort |
awk -F, '
$1 == LastState { 
    print "\t" $2 
}
$1 != LastState { 
    LastState = $1
    print $1 
    print "\t" $2
}'
share|improve this question

2 Answers 2

Your script byState may not be executable.

Try:

chmod +x byState

... to make the script executable, then try your command line again.

Additionally, or alternatively, because Unix doesn't include the current directory in the path by default, you may need to write:

sed -f nameState list | ./byState

... instead of

sed -f nameState list | byState
share|improve this answer
    
I tried using the "./byState", and it worked!! Thank you so much. I should have asked sooner. –  user246562 Aug 19 '13 at 1:19
    
Glad to help. If this answer has solved your problem, please go ahead and check the answer as accepted. –  Simon Aug 19 '13 at 2:22

you might try this:

sed -f namestate list | sort -k 4 -t ,
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.