I'm on Linux version 2.6.32-696.3.1.el6.x86_64, using the Ksh shell.
I'm working with the input file:
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
My sed script "nameState" changes the 2-character state abbreviation to the full state name:
s/ CA/, California/
s/ MA/, Massachusetts/
s/ OK/, Oklahoma/
s/ PA/, Pennsylvania/
s/ VA/, Virginia/
I issued the sed and awk command within the command shell in emacs:
sed -f nameState list | awk -F, '{ print $4 ", " $0 }' > output
when I edit this file in Emacs I see:
Massachusetts^M, John Daggett, 341 King Road, Plymouth, Massachusetts
Virginia^M, Alice Ford, 22 East Broadway, Richmond, Virginia
Oklahoma^M, Orville Thomas, 11345 Oak Bridge Road, Tulsa, Oklahoma
Pennsylvania^M, Terry Kalkas, 402 Lans Road, Beaver Falls, Pennsylvania
Massachusetts^M, Eric Adams, 20 Post Road, Sudbury, Massachusetts
Virginia^M, Hubert Sims, 328A Brook Road, Roanoke, Virginia
California^M, Amy Wilde, 334 Bayshore Pkwy, Mountain View, California
Massachusetts^M, Sal Carpenter, 73 6th Street, Boston, Massachusetts
which seems to be the output I want, except that it includes a ^M
(carriage return?)
but when I issue the command cat output
, I see:-
, John Daggett, 341 King Road, Plymouth, Massachusetts
, Alice Ford, 22 East Broadway, Richmond, Virginia
, Orville Thomas, 11345 Oak Bridge Road, Tulsa, Oklahoma
, Terry Kalkas, 402 Lans Road, Beaver Falls, Pennsylvania
, Eric Adams, 20 Post Road, Sudbury, Massachusetts
, Hubert Sims, 328A Brook Road, Roanoke, Virginia
, Amy Wilde, 334 Bayshore Pkwy, Mountain View, California
, Sal Carpenter, 73 6th Street, Boston, Massachusetts
Why am I not seeing the state in the first field of this file? How can I get rid of the ^M
carriage return that the awk command seems to insert?
Thanks for your help!