Re: Help with NAWK
From: Chris F.A. Johnson (c.f.a.johnson_at_rogers.com)
Date: 07/31/03
- Next message: Binner: "sed translation"
- Previous message: scriptOmatic: "Re: Help with NAWK"
- In reply to: Shiva MahaDeva: "Help with NAWK"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 Jul 2003 05:21:52 GMT
On Thu, 31 Jul 2003 at 02:17 GMT, Shiva MahaDeva wrote:
> Look this file:
>
> solaris> cat car_models
>
>
> volks golf-$5000
> ford taurus-$68500
> chevrolet vectra-$600000
>
> Using NAWK, how could I extract the price string , in the second field
> (with the dolar sign ) ?
Why use any kind of awk; cut will do the job.
But whichever utility you use, the principle is the same: set the
field delimiter to a hyphen and print the second field:
awk 'BEGIN { FS = "-" } {print $2}' car_models ## or gawk or nawk
Or:
cut -d- -f2 car_models
Or:
while IFS=- read a price
do
echo "$price"
done < car_models
Or (a little differently, delete everything up to and including
the hyphen):
sed 's/.*-//' car_models
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2003, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: Binner: "sed translation"
- Previous message: scriptOmatic: "Re: Help with NAWK"
- In reply to: Shiva MahaDeva: "Help with NAWK"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|