Solved

File search and manipulation

Posted on 1998-08-10
4
214 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

771 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

11 Experts available now in Live!

Get 1:1 Help Now