Solved

File search and manipulation

Posted on 1998-08-10
4
215 Views
Last Modified: 2010-04-21
I have a file which contails a list of error codes
e.g
-1730
-177


Etc.....

I also have a file with a copy of these codes followed by there meaning/action etc

I would like to use first file to reference the second and print the error code in the second to a STD display. each code in file one may occure more than once but they must be displayed in the prder in which the appear in the first file.

I have no Idea how easy or hard this is to do so 100 Pts allocated and we'll go from there
0
Comment
Question by:dramsden
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
aledonne earned 100 total points
ID: 2009215
How easy it will be depends on the language you want to use to do the job. It would be very straightforward in Perl, for example... You are using the second file as a hash table, then for each error code, print (to your output file, STDOUT, STDERR, wherever) the appropriate hash table entry.

I suggest Perl because this is exactly the sort of thing it was designed for... it's a "Practical Extraction & Reporting Language".
0
 
LVL 1

Author Comment

by:dramsden
ID: 2009216
Can you give me an example. currently it's just in the c shell and I'd really like to keep it that way but if I can't then alternatives will be considered.
I have extensive programming knowledge, however I've never (Until this week ) been anywhere near UNIX so it been a but of an eye opener to me. (background in DOS/MVS NT enviroments) I see the power of the OS but boy everything seems so long winded.
I await your comments

Regards


0
 
LVL 1

Expert Comment

by:aledonne
ID: 2009217
Okay... assuming:
1/ Your list of error codes is formatted like your example - one per line. We'll call it errlog.txt.

2/ Your second file has code#, tab, description - one per line. We'll call it errcode.txt. Obviously, it can be adapted for any consistent formatting.

So you can follow this more easily, $_ is the "default pattern matching space" - it's initialized as the contents of current line of the currently open file handle at the beginning of the current scope.

The actual script is just a dozen lines... most of what is below is comments.

---------Begin sample code---------

#!/usr/bin/perl

# Create the hash table.
open(CODES, "<errcode.txt");

# For each line of input...
while (<CODES>) {

# Split the line ($_) on the Tab into the code & the description
    ($code, $description) = split(/\t/, $_, 2);

# Make a corresponding entry in our table
    $CodeHash{$code} = $description ;
}
# Clean up & play nice
close (CODES) ;

# Now, for each error in the "log"...
open(LOG, "<errlog.txt") ;

while (<LOG>) {
# Remove the trailing newline
    chomp;          # Same as chomp($_);

# Check for validity
    if (defined $CodeHash{$_}) {

# Print output to stdout (this could be redirected)
        print "$_\t $CodeHash{$_}";
    } else {
        print "$_\t Unknown error code.\n";
    }
}
# Clean up again.
close (LOG);
0
 
LVL 1

Author Comment

by:dramsden
ID: 2009218
Ugh !!!!!!!

Thanks for the above

I'll go through it with my new PERL book and see if I can bet it working (and understand why) and I'll get back to you.

I should be back in touch today. Any other tips or web sites to visit to GEN up on Unix and all the problems a novice user may come across would also be gratefully received.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now