gawk scripting question
Hi, I was wondering per chance in anyone could lend a hand with something I am having difficulty doing,
How would I go about writting a script called "display" using gawk for data processing in the script, using a single argument such as, $./display 1998 Outputing each line in a file called cars, and add a new columb of "mileage per year". If the car is older than the specified argument mark with "*" at the beginning of the line. An example would be, $./display 1998 *lym fury 1970 73 2500 1.825 chevy malibu 1999 60 3000 5.455 *ford mustang 1965 45 10000 1.000 volvo s80 1998 102 9850 2.143 Any help would be apreciated, and if you just want to heckle, I implore you to at least make it funny. lol Any help you would greatly appreciated! |
More input ... which of those output columns is the "newly added"?
Are all cars identified by two words? Cheers, Tink |
Smells very much like homework to me.
If so, we'll guide you, but we won't do your work for you. So show us what you've done already, and exactly where you're having problems and we'll help you to work through them. And please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. |
Quote:
There is no newly added, all the cars are like that, chevy in one column, malibu in the next column et-cetera. So all the cars are identified by two words, brand and make of the car so to speak. THen the other coulumb will be the year of the car, the next column miles, etc. It's very tricky and have been wrestling with this one for awhile but to no avail as of yet unfortunately. |
Quote:
|
It looks like basic awk job (compare value with a field value, print...), where are you stuck ?
|
Quote:
This is all I've been able to come up with thus far as kind of a rough sketch. #!usr/bin/gawk -f BEGIN{ print " Miles" print "Make Model Year (000) Price" print \ "----------------------------------------" } { if $3 < ( if ($1 ~ /ply/) $1= "plymouth" if ($1 ~ /chev/) $1= "chevolet" printf "%-10s %-8s %2d %5d $ %8.2f\n,\ $1, $2, $3, $4, $5 } |
Quote:
Would it be basic for you to hit a homerun in a major league baseball park agains professional pitching too? lol |
Code:
[demo@localhost bin]$ cat cars Note: F 1920 70 2000 = 1: "Car's Brand" 2: "Year" 3: "Km/Per Ltr" 4: "Run Total Kms" Do you calculations there as per your requirement. But the above code answers your basic question: Asterisk-Mark Lines that do not contain a specified Year and add a Column that says blah blah! |
Quote:
Code:
awk -v y=1998 '{if($3 < y) printf "*"; print}' cars_file.txt |
Quote:
Quote:
Cheers, Tink |
Hello again all, making some progress with your help but more help would be greatly appreciated!
|
What is the 4th field on:
Quote:
I used a file named car.txt with the content: Code:
lym fury 1970 73 2500 1.825 Code:
*lym fury 1970 (73) 2500 $1.825 Code:
#!/usr/bin/awk -f Code:
./display.sh -v y=1979 cars.txt The entry that I used is right? |
Hi, I'm trying ot make it function from a file called cars, in the file "cars" it has the following,
plym fury 1970 73 2500 chevy malibu 1999 60 3000 ford mustang 1965 45 10000 volvo s80 1998 102 9850 ford thundbd 2003 15 10500 chevy malibu 2000 50 3500 bmw 325i 1985 115 450 honda accord 2001 30 6000 ford taurus 2004 10 17000 toyota rav4 2002 180 750 chevy impala 1985 85 1550 ford explor 2003 25 9500 |
Quote:
I do find programming to be interesting though and I have just become intorduced ot linux programming only a couple of months ago, so though there is much I have to learn, I don't beleive even excellent programmers "knew it all" within three months. lol Thank you for your reply though I really appreciate it, well besides the part that tried to discourage me from learning more about linux programming, because I do find some of it kind of interesting and am going ot continue to learn more on my own even after this month. I'm going to try and tweak that code you came up with so it works for all years I type in, thanks man!!! |
All times are GMT -5. The time now is 08:39 PM. |