Solved

File search and manipulation

Posted on 1998-08-10
4
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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.
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.

739 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