Slow Running Script (Reading 8000 lines)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Slow Running Script (Reading 8000 lines)
# 8  
Old 07-24-2013
Working flawless. Running time is under a second.

Thank you.

I can see the barebones logic but struggling a bit with the syntax. Could you explain a bit more what the lines are actually doing.
# 9  
Old 07-24-2013
Here is a fully commented version of the script:
Code:
awk -F= '               # Set field separator to "="
# 1st two input files consist of pairs of lines using the format:
#               name=user
#               gud=value
# in this order.
# So with FS set to "=", $1 will be "name" or "gud" and $2 will be the name of
# the user or the value associated with that user name.

# 3rd input file consists of lines using the format:
#               user

# f     number of files seen
# lf    name of last file seen
# u     user from name=user line in 1st two input files
# r1[u] recorded value from 1st file from gud=value line for name u
# r2[u] recorded value from 2nd file from gud=value line for name u
FILENAME != lf {        # If this is the first time we have a line from this file
        f++             # increment the number of files seen and
        lf = FILENAME   # save the name of the current file for comparison.
}
$1 == "name" {          # If this is a name= line in 1 of the 1st 2 files,
        u = $2          # save the user name, and
        next            # skip to next input line.
}
$1 == "gud" {           # If this is a gud= line in 1 of the 1st 2 files...
        # If we are processing a line from the 1st file, set r1[] for the
        # current user name to the value found on this line from the 1st input
        # file; otherwise set r2[] for the current user name to the value found
        # on this line from the 2nd input file.
        f == 1 ? r1[u] = $2 : r2[u] = $2
}
f == 3 {                # If this line is from the 3rd input file...
        # If the user on this line was not in either of the 1st 2 files, save
        # the name in no_results.out.
        if(!($1 in r1) && !($1 in r2)) print > "no_results.out"
        # otherwise,
        # if the user on this line was not in one of the 1st 2 files or if the
        # value associated with this user was an empty string in one of the
        # files, save the name in no_gud.out.
        else    if(!($1 in r1) || r1[$1] == "" ||
                   !($1 in r2) || r2[$1] == "") print > "no_gud.out"
        # otherwise,
        # if the value for the user is different in the 1st 2 files, save the
        # name in no_matches.out.
        else    if(r1[$1] != r2[$1]) print > "no_matches.out"
        # otherwise,
        # the user is in both files and the values match; save the name in
        # matches.out.
        else    print > "matches.out"
}' File2 File3 File1    # The input files are File2, File3, and File1


Last edited by Don Cragun; 07-24-2013 at 04:13 PM.. Reason: fix typo
This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 07-24-2013
Extremely helpful - much appreciated.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script reading file slow

I have shell program as below #!/bin/sh echo ======= LogManageri start ========== #This directory is getting the raw data from remote server Raw_data=/opt/ftplogs # This directory is ready for process the data Processing_dir=/opt/processing_dir # This directory is prcoessed files and... (4 Replies)
Discussion started by: Chenchireddy
4 Replies

2. AIX

AIX server running very slow

Hello, All the commands on AIX are running very slow. Below is few stats but I didn't find any issue in cpu or memory reosurces vmstat System configuration: lcpu=4 mem=6144MB ent=1.00 kthr memory page faults cpu ----- -----------... (2 Replies)
Discussion started by: Vishal_dba
2 Replies

3. UNIX for Dummies Questions & Answers

Ubuntu seems running slow!

Hello, My PC seems running slow: OS32 system, Pentium(R)4---2.40Ghz, 1GB RAM, 80GB HDI am running Ubuntu 11.10 (Oneiric Ocelot) alone in this box, which seems very slow to me. Is this normal? Compared with my other PC (Running XP) with 1.99GHz AMD Athlon 3200+, 2GB RAM,500GB HD, XP and Mint... (11 Replies)
Discussion started by: yifangt
11 Replies

4. Shell Programming and Scripting

awk script - reading input lines

Can I do something like, if($0==/^int.*$/) { print "Declaration" } for an input like: int a=5; If the syntax is right, it is not working for me, but I am not sure about the syntax. Please help. Thanks, Prasanna (1 Reply)
Discussion started by: prasanna1157
1 Replies

5. Shell Programming and Scripting

script for reading logs of a script running on other UNIX server

Hi, I have a script, running on some outside firwall server and it's log of success or failure is maintained in a file. I want to write a script which ftp that server and reads that file and checks the logs and if failure , I will send mail notification. Please let meknow if I am not... (1 Reply)
Discussion started by: vandana.parwani
1 Replies

6. Shell Programming and Scripting

Reading multi lines variable using shell script

Hi, I am using #!/bin/sh shell. I have a variable which contains multi line data. I want to read that variable line by line. Can someone post the code to read the multi line variable line by line? Any help is much appreciated. (2 Replies)
Discussion started by: gupt_ash
2 Replies

7. UNIX for Dummies Questions & Answers

Unix is running slow??

All, This is my interview questions. Let me explain the question. Some one is asking me that, the unix server is running very slow. As a unix unix admin, what are the steps we should follow?? What/which process we should check?? What is the way to find the root cause ? Please let me know.... (8 Replies)
Discussion started by: govindts
8 Replies

8. HP-UX

SAM running slow

Any ideas on why SAM would take so long to load and initialize? (4 Replies)
Discussion started by: csaunders
4 Replies

9. SCO

Server running slow

Hi, Wonder is someone can help. I've got a server SCO_SV 3.2v5.0.7 PentIII that is located at a different site and is running slow and has been for a week. I've been speaking to a third party who say nothing is wrong with it but its still running slow. The 3rd party advise it could be a... (2 Replies)
Discussion started by: tez
2 Replies

10. Solaris

Solaris running very slow!!

Hi all, Solaris is working very slow as login to solaris takes time say after 10 to 15 mins we get the login prompt back after logging in as oracle account/other account. This causes most Batch run delays(DWHouse jobs) scheduled through cronjobs. Where should one look for such issues to... (3 Replies)
Discussion started by: a1_win
3 Replies
Login or Register to Ask a Question