C Shell problem: using a key from one file to find data in another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting C Shell problem: using a key from one file to find data in another
# 1  
Old 12-03-2009
C Shell problem: using a key from one file to find data in another

I've never written scripts (just switched from Ada to C++). I have a book that's over my head and a few examples, other then that I'm floundering. Everything here at work is being done in C Shell. None of the C++ programmers are experienced in shell scripting.

I have a data file with the following format, "key" words in bold:

-------------------------------------------
{header info: 20 lines}

DATA_POINT 99
DATA_HEADER
TYPE: AppendNewRecordStruc
NAME: AppendNewRecordStruc
TITLE: AppendNewRecordStruc
SOURCE: N/A
END_DATA_HEADER
DEFINITIION
SOURCE_FILE: K:/home/source_code/my_code.C
DATA: append_new_struc
END_DEFINITION
END_DATA_POINT

DATA_POINT 100
DATA_HEADER
TYPE: DeleteRecordStruc
NAME: DeleteRecordStruc
TITLE: DeleteRecordStruc
SOURCE: N/A
END_DATA_HEADER
DEFINITIION
SOURCE_FILE: K:/home/source_code/my_code.C
DATA: del_struc
END_DEFINITION
END_DATA_POINT

END_FILE
-----------------------------------------------

After I run this through an in-house tool, I get a log file listing the errors. However the log is thousands of lines, and only some of these lines are relevent to me. For example:
-----------------------------------------------

{header}

The entry for Data_Point #99 could not be processed.
The entry for Data_Point #100 could not be processed.
The entry for Data_Point #101 processed successfully.
{irrelevent error messages}
The entry for Data_Point #212 processed successfully.
The entry for Data_Point #211 could not be processed.
{irrelevent error messages}
-----------------------------------------------

I'd like to take the log file, cross reference it back to the original data file and come up with something useful. A new file listing only the failed points with the format

POINT..........NAME....................................DATA
99...............AppendNewRecordStruc............append_new_struc
100..............DeleteRecordStruc..................del_struc

...'s are blank spaces


Any help would be greatly appreciated.

Steve

Last edited by bassmaster; 12-03-2009 at 04:26 PM.. Reason: formatting of desired output not clear
# 2  
Old 12-03-2009
need a little more info... but here's how you might grab points of interest and then grep them from another file:

Code:
#!/bin/ksh

for point in `grep "The entry for Data_Point.*process.*" log | sed -e 's/^.*#//' -e 's/ .*$//'` ; do

print "POINT NAME $point DATA"
grep "^$point " point_data.file

done


Last edited by quirkasaurus; 12-03-2009 at 03:22 PM.. Reason: added ksh specifically
# 3  
Old 12-03-2009
Thanks. That will give me a starting point at least, if not more. I modified the original output to be clearer. It had formatted oddly, the confusion was my fault.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. Shell Programming and Scripting

Replace data of a file with data from another file using shell scripting.

Dears, I'm new to shell scripting and i was wondering if you can help me with following matter. I have a file containing 400,000 records. The file contains two columns like: 00611291,0270404000005453 25262597,1580401000016155 25779812,1700403000001786 00388934,1200408000000880... (1 Reply)
Discussion started by: paniklas
1 Replies

4. Shell Programming and Scripting

Find and replace value using a key from other file

Dear Friends, I am looking for a way how to find and replace a value in two files using a reference a file where are the key to replace. Basically, I want to keep a copy of the original file and make a new one in order to compare at the end that the change was done whitout change the rest of... (26 Replies)
Discussion started by: jiam912
26 Replies

5. Homework & Coursework Questions

Shell script calling Perl function, sort and find data, write to new files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies

6. Shell Programming and Scripting

Shell script to find specific file name and load data

I need help as to how to write a script in Unix for the following: We have 3 servers; The mainframe will FTP them to a folder. In that folder we will need the script to look and see if the specific file name is there and load it to the correct table. Can anyone pls help me out with... (2 Replies)
Discussion started by: msrahman
2 Replies

7. Shell Programming and Scripting

Using Key to get data from second file

I posted a problem last week that had essentially two steps. Someone was kind enough to help me with the first step, but beacuse I didn't explain things well, left out the second step. I'm required to work in C Shell. I deeply appreciate any help, since I've never worked in a shell language... (4 Replies)
Discussion started by: bassmaster
4 Replies

8. Shell Programming and Scripting

Find and replace data in text file with data in same file

OK I will do my best to explain what I need help with. I am trying to format an ldif file so I can import it into Oracle oid. I need the file to look like this example. Keep in mind there are 3000 of these in the file. changetype: modify replace: userpassword dn:... (0 Replies)
Discussion started by: timothyha22
0 Replies

9. Shell Programming and Scripting

Simple shell script to find and print data

Hi, I have a log file containing data on emails sent. Looks a bit like this for one email: Content-Type: text/plain; charset="UTF-8" Date: 12 Jun 2008 14:04:59 +0100 From: from@email.com Subject: xcf4564xzcv To: recip@email.co.uk Size = 364 Jun 12 14:04 smtp_234sldfh.tmp I need to... (5 Replies)
Discussion started by: terry2009
5 Replies

10. UNIX for Advanced & Expert Users

Problem with find command in C-shell

when i use the following command find / -name '*.*' -exec grep -il 'text' {} \; I can redirect the errors to /dev/null. This happens only in ksh but not in csh. the 2>/dev/null is not working in csh. Can you some one suggest an alternative for this in csh ? (3 Replies)
Discussion started by: dhanamurthy
3 Replies
Login or Register to Ask a Question