Solved

File search and manipulation

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix originating lp print jobs, are shown in Windows print queue with owner username + source ip 1 108
auto mounter on solaris 1 67
Unix Question 19 50
Martian Packets Unix 5 67
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…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
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.

792 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