Hello, I have a file with a list of car makes and specific information for each make. An example is:
@Audi :Warranty
@Audi :Pricing
@Audi :Colors
@Acura :Warranty
@Acura :Pricing
@Acura :Colors
and so on through a bunch of makes. I need to make a list in a selection box of just one name of each make. For example:
Audi
Acura
BMW
Buick
Any help is muchly appreciated! Thanks!
awk -F"[@:]" '$2!=prev { print $2; prev=$2 }' datfile
awk -F"[@:]" ' {a[$2]} END { for(e in a) print e} ' infile
My solution keeps records in order of file - if this is important.
This requires the inputfile be sorted.
thru sed..
sed 's/@\(.*\):.*/\1/g' inputfile |uniq > outfile
awk -F \: '{print $1}' infile.txt|sed 's/@//g' |uniq
Nicely alphabetically sorted
awk -F'[@:]' '{print $2}' infile | sort -u
sed 's\@\\;s\:.*\\' infile | sort -u
No sort:
awk -F'[@:]' '!A[$2]++{print $2}' infile
ygemici
November 30, 2010, 4:17am
9
# sed -n 's/^@//;s/:.*//p' infile | sed -e :x -e 'N;s/\(.*\)\n\1/ \1/' -e 'tx'|sed 's/ */\n/g;s/^\n//g'
rdcwayx
November 30, 2010, 5:53am
10
Just saw the same command already given.
awk -F"[@:]" '!a[$2]++{print $2}' infile
awk -F"[@:]" '!_[$2]++{print $2}' infile
...Edit...
oh...i didn't see the replies on the second page. My bad!!!
Thanks, I got all the car makes put into a selection box! I want people to be able to pick a make and then pick an option. For example: Select Audi in the selection box and then have the options (warranty, price, color) in checkboxes.
I need the script to pull out the options from the file, they can't be hard coded. All the options follow the ":" For example:
@Audi :Warranty (Warranty is the option)
Thanks
Something like this?
awk -F'[@:]' '$2==b{print $3}' b=Audi infile