Solved

File search and manipulation

Posted on 1998-08-10
4
216 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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 how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

777 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