Using Key to get data from second file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Key to get data from second file
# 1  
Old 12-07-2009
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 before.

I have a data file and a log file with the following formats:

Data.File
Quote:
DATA_POINT 99
DATA_HEADER
TYPE: AppendNewRecordStruc
NAME: AppendNewRecordStruc
END_DATA_HEADER
DEFINITIION
SOURCE_FILE: K:/home/source_code/my_code.C
DATA: append_new_struc
END_DEFINITION
END_DATA_POINT
Log.File
Quote:
{irrelevent error messages}
The entry for Data_Point #98 processed successfully.
The entry for Data_Point #99 could not be processed.
{irrelevent error messages}
The entry for Data_Point #100 could not be processed.
{irrelevent error messages}
I need to generate a list of failed points with their NAME and DATA information. Somone helped me with a method for extracting the "key" from the log file.

Quote:
#!/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
However, I still have no idea how to find the entry in the data file by the key, then extract the NAME and DATA from the lines that follow the key.

The output should look similar to the following (...'s are for spacing only):

Quote:
POINT..........NAME....................................DATA
99...............AppendNewRecordStruc............append_new_struc
100..............DeleteRecordStruc..................del_struc
# 2  
Old 12-07-2009
I'm confused.

You say "I'm required to work in C Shell" but the script you post is Korn shell.

Also, that script uses sed and grep, so is it safe to assume that you really do NOT need to work in csh?

You could process this easily with Perl or Awk, more clumsily with sed and grep.

So what does csh really have to do with anything??
# 3  
Old 12-07-2009
Quote:
Originally Posted by TonyLawrence
I'm confused.

You say "I'm required to work in C Shell" but the script you post is Korn shell.

Also, that script uses sed and grep, so is it safe to assume that you really do NOT need to work in csh?

You could process this easily with Perl or Awk, more clumsily with sed and grep.

So what does csh really have to do with anything??
I'm so new to scripting that I'm not sure I understand your questions, but I'll answer them best I can. (I'm an Ada programmer trying to jump into a C++ shop.) All of the scripts here are old and written in .csh files. I was told by someone that they are C Shell scripts and that's what we are required to use. Some of these scripts do use sed and grep.

The script that I posted was a response that I received from a similar question. I was not aware it was a Korn shell script.

If you are saying that this is an easy task in Awk, well that might be, but I don't know Awk either. Also, this is a task that I or sopmeone else will need to perform about once a month, so having it in a .csh file should be useful.

Thanks for reading my question. Any help is greatly appreciated.

Last edited by bassmaster; 12-08-2009 at 10:04 AM..
# 4  
Old 12-09-2009
Deleted

Last edited by bassmaster; 12-09-2009 at 03:32 PM..
# 5  
Old 12-10-2009
Try:

Code:
echo "POINT   NAME     DATA"
for each in `awk -F"[ #]" '/[0-9]+/{ print $6 }' log`
do 
awk '/'$each'$/ { f=1} f&&(c++==3) { n=$NF } f&&(c==8) {d=$NF } f&&n&&d { print '$each'"\t"n"\t"d; n="";d="";f=0 }' dat
done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate Join clause based on key data

Hi, I have a file pk.txt which has pk data in following format TableName | PK Employee | id Contact|name,country My Output should be Employee | t1.id=s.id Contact| t1.name=s.name AND t1.country=s.country I started of like this: for LIST in `cat pk.txt` do... (5 Replies)
Discussion started by: wahi80
5 Replies

2. Shell Programming and Scripting

Searching the content of one file using the search key of another file

I have two files: file 1: hello.com neo.com,japan.com,example.com news.net xyz.com, telecom.net, highlands.net, software.com example2.com earth.net, abc.gov.uk file 2: neo.com example.com abc.gov.uk file 2 are the search keys to search in file 1 if any of the search key is... (3 Replies)
Discussion started by: csim_mohan
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

Extract header data from one file and combine it with data from another file

Hi, Great minds, I have some files, in fact header files, of CTD profiler, I tried a lot C programming, could not get output as I was expected, because my programming skills are very poor, finally, joined unix forum with the hope that, I may get what I want, from you people, Here I have attached... (17 Replies)
Discussion started by: nex_asp
17 Replies

5. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

6. Solaris

Solaris 8 ssh public key authentication issue - Server refused our key

Hi, I've used the following way to set ssh public key authentication and it is working fine on Solaris 10, RedHat Linux and SuSE Linux servers without any problem. But I got error 'Server refused our key' on Solaris 8 system. Solaris 8 uses SSH2 too. Why? Please help. Thanks. ... (1 Reply)
Discussion started by: aixlover
1 Replies

7. Linux

SSL/TLS uses the public key to encrypt data ?

Hi, I have a doubt..whether the SSL/TLS protocol uses the public key of the web server to encrypt data before sending it. I knew the browser verifies the public key of the web server using the digital certificate (by verifying the signature of the certificate using trusted authority). whether... (2 Replies)
Discussion started by: chaitus.28
2 Replies

8. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: bassmaster
2 Replies

9. UNIX for Dummies Questions & Answers

Pressing backspace key simulates enter key

Hi, Whenever i press the backspace key, a new line appears, i.e. it works like a enter key. :confused: Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies
Login or Register to Ask a Question