Awk Script that implements a report writer

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Awk Script that implements a report writer
# 8  
Old 12-01-2010
Hi,

English is not my native language, so i hope i can explain myself properly and you can understand me.


Perhaps may exists another way to get it, but the 'sort' command reads the data with a field separator (space by default). I want to sort the output using the sales amount, and would be the fourth word in most of the lines, but it would be wrong with this line

Code:
Buck, Fast                      Stock Boy                            2398.89

because the fourth word would be 'Boy', not the amount, so the sorting would fail. I need another field separator regardless of the name and position strings.

Regards,

Birei
# 9  
Old 12-01-2010
ok, thanks. One more thing, I am not familiar with the match() function and I'm not sure if I'm supposed to use it, is there another way of getting a[1] and a[2]?
# 10  
Old 12-01-2010
Hi,

Several ways, here two of them:
Code:
$ tail -n6 report
END {
    for (s in sales) {
    split(s, a, ":");
    printf("%-30s\t%-20s\t%20.2f\n", a[1], a[2], sales[s]) | "sort -t\"\t\" -nr -k3"
    } 
}

$ tail -n7 report
END {
    for (s in sales) {
    a1 = substr(s, 0, index(s, ":")-1)
    a2 = substr(s, index(s, ":")+1)
    printf("%-30s\t%-20s\t%20.2f\n", a1, a2, sales[s]) | "sort -t\"\t\" -nr -k3"
    } 
}

Regards,
Birei
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to implements Queueing Using Shell scripts

I want to implement a control mechanism using Shell scripts .The intention is to have controlled number of jobs running in parallel External process will kickstart 40 jobs in parallel .All the 40 jobs will call the same generic script with different parameter values .But at a time only 2 should... (1 Reply)
Discussion started by: police
1 Replies

2. Homework & Coursework Questions

awk script that implements a report writer

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The script should compute the sale amounts per associate for the year 2009 and print them in a sorted list ranked... (1 Reply)
Discussion started by: Jeffthrow5
1 Replies

3. HP-UX

How Unix implements virtual memory?

Hello! just wanna ask if how UNIX implements virtual memory, and how it handles page faults, working sets, page sizes and how it reconciles thrashing issues? if you know some sources where I can have some idea, just post it here. thx (1 Reply)
Discussion started by: kjcruz
1 Replies

4. Homework & Coursework Questions

How Unix implements virtual memory?

Use and complete the template provided. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The key to using memory most efficiently is virtual memory management. Consider both Windows and UNIX operating systems. Compare and contrast how each... (0 Replies)
Discussion started by: kjcruz
0 Replies

5. Shell Programming and Scripting

Awk Script for generating a report

Hi all, I have a log file of the below format. 20081016:000042 asdflasjdf asljfljs asdflasjf safjl 20081016:000229 /lask/ajlsdf/askdfjsa 20081016:000229 /lashflas /askdfaslj hsfhsahf 20081016:000304 lasflasj ashfashd 20081016:000304 lajfasdf ashfashdfhs I need to generate a... (3 Replies)
Discussion started by: manoj.naidu
3 Replies

6. AIX

Probleme with DVD Writer

I can write into DVD? I have USE "MKCD" command mkcd -r directorie -d /dev/cd1 please help me it s urgent (2 Replies)
Discussion started by: mktahar
2 Replies

7. UNIX for Advanced & Expert Users

Probleme With DVD Writer

I Use mkcd for save same directories into DVD, But the commande not complete succefuly mkcd -r directorie_i_whish_save -d /dev/cd1 please it is very urgent thank you :confused: :confused: (1 Reply)
Discussion started by: mktahar
1 Replies

8. UNIX for Dummies Questions & Answers

Share CD-Writer

Hi, guys ! I have a server that runs FreeBSD 5.3 and on that server a have a CD-Writer used for backup. The question is, does anybody know how can I share this CD-Writer ? I want to be able to write CDs from another computer, without transfering all the data to the server and after that use all... (2 Replies)
Discussion started by: Sergiu-IT
2 Replies
Login or Register to Ask a Question