Trying to get example from Awk and Sed book to work on Ubuntu 13.04

0

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
}'

user246562

Posted 2013-08-19T00:23:37.820

Reputation: 1

Answers

0

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

Simon

Posted 2013-08-19T00:23:37.820

Reputation: 611

I tried using the "./byState", and it worked!! Thank you so much. I should have asked sooner. – user246562 – 2013-08-19T01:19:42.960

Glad to help. If this answer has solved your problem, please go ahead and check the answer as accepted. – Simon – 2013-08-19T02:22:48.077

0

you might try this:

sed -f namestate list | sort -k 4 -t ,

Endoro

Posted 2013-08-19T00:23:37.820

Reputation: 2 036