Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends,

I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving...

File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy the valid string/lines to a output .CSV file based on the given search criteria.

I have attched the joblist and log file for your reference. Any early help would be greatly appreciated.

Thanks,
NK

You have mentioned three input files but only included two, and not clearly mentioned which is A, which is B, and which is C(missing).

If they are short, it would be just as easy to paste them into your post using code tags: {code}stuff{/code} except with [] instead of {}.

File A is joblist.txt
File B is job.log
File C would be an extended log of job.log, which is quite huge for me to upload here.

I have tried the below script and only the list from joblist gets stored in the output file.

awk '
FILENAME=="joblist.txt" {
for(i=1;i<=NF;i++ ) {Keys[$i]++}
}
FILENAME=="job.log" {
found=0
for(i=1;i<=NF;i++)
{ if(Keys[$i]>0) {found++; }}
if (found != 2 ) {
print $0; found = 0; break;
}
}
' joblist.txt job.log >>diff.csv

---------- Post updated 10-11-12 at 11:12 AM ---------- Previous update was 10-10-12 at 01:05 PM ----------

hello Friends, Can you someone respond to this request.

What output would you expect from the above files? Without seeing that, we're just guessing.

Hi Corona,

Expected output would be the list of lines that match with the job_ids that are present in the joblist.txt file.

Bascially, compare the list of job_ids present in the joblist.txt, with the job.log file and write only the lines that are matching with the job_ids >>to the output file

Thanks,
NK

Note of the job_ids on the joblsit file are on the log file. Some jobs are listed in over 60 lines on the log file. Are those lines to be put on CSV file? Are all lines that match (if there was a match) to be put on a CSV file?

All the lines in the job log that match to the job_ids requires to be put on a csv file

Thanks,
NK