Operating System - HP-UX
1752619 Members
4638 Online
108788 Solutions
New Discussion юеВ

Re: Reading two files with awk

 
SOLVED
Go to solution
Chris Frangandonis
Regular Advisor

Reading two files with awk


Hi All,

I have a problem in reading file 1 , which consist of data and file 2 which has the e-mail address

Script
======

awk '{
while ((getline b_n < "LDC_Snapshot_Status.ini") > 0)
while( getline line < "NUM_CORR" > 0 )
if(line~/:/){
split(line,as," ")
print echo "Call from "as[1]" to "as[2]" in "as[8]" is in progress for "as[7]" days since "as[3]" to date. ""Please forward this mail to the relevant persons." "| mailx -s " "\"LDC_Snapshot_Status\" " b_n
}' NUM_CORR


NUM_CORR
========
00260976007053 0112101104 2008/11/01 00:21:03 2008/11/26 22:21:04 26 rjdf:01
00260976007053 0112101105 2008/11/18 00:29:12 2008/11/26 22:29:13 8 rjnl:01

LDC_Snapshot_Status.in
======================
me@mail.com
you@mail.com

The result should look like
============================

Call from 00260976007053 to 0112101104 in rjdf:01 is in progress for 26 days since 2008/11/01 to date. Please forward this mail to the relevant persons.| mailx -s "LDC_Snapshot_Status" me@mail.com
Call from 00260976007053 to 0112101104 in rjdf:01 is in progress for 26 days since 2008/11/01 to date. Please forward this mail to the relevant persons.| mailx -s "LDC_Snapshot_Status" you@mail.com
Call from 00260976007053 to 0112101105 in rjnl:01 is in progress for 8 days since 2008/11/18 to date. Please forward this mail to the relevant persons.| mailx -s "LDC_Snapshot_Status" me@mail.com
Call from 00260976007053 to 0112101105 in rjnl:01 is in progress for 8 days since 2008/11/18 to date. Please forward this mail to the relevant persons.| mailx -s "LDC_Snapshot_Status" you@mail.com


Thanks
Chris
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: Reading two files with awk

Hi Chris:

There is a spelling inconsistency in your file in the script and the external post. Either "LDC_Snapshot_Status.ini" or "LDC_Snapshot_Status.in".

You are lacking a number of opening and closing braces too.

You need to *close* the "NUM_CORR" file at the end of the 'while' loop that reads it for every iteration of the outer 'while' loop that reads the "LDC*" file.

awk '{
{
while ((getline b_n < "LDC_Snapshot_Status.in") > 0) {
while( getline line < "NUM_CORR" > 0 ) {
if (line~/:/) {
split(line,as," ")
print echo "Call from "as[1]" to "as[2]" in "as[8]" is in progress for "as[7]" days since "as[3]" to date. ""Please forward this mail to the relevant persons." "| mailx -s " "\"LDC_Snapshot_Status\" " b_n
}
}
close "NUM_CORR"
}
}' NUM_CORR

...try this variation.

Regards!

...JRF...
Chris Frangandonis
Regular Advisor

Re: Reading two files with awk

Hi James,

Thanks it works. The problem with spelling and braces was due to copy and paste ...

Small mistake in your script

awk '{
{ <------- and additional braces

Thanks a lot

Chris
James R. Ferguson
Acclaimed Contributor

Re: Reading two files with awk

Hi (again) Chris:

It would be cleaner, given that you explicitly read both files, to wrap the script in a BEGIN block and eliminate the useless read of NUM_CORR. Something like:

#!/usr/bin/awk -f
BEGIN {
while ((getline b_n < "LDC_Snapshot_Status.in") > 0) {
while( getline line < "NUM_CORR" > 0 ) {
if (line~/:/) {
split(line,as," ")
print echo "Call from "as[1]" to "as[2]" in "as[8]" is in progress for "as[7]" days since "as[3]" to date. ""Please forward this mail to the relevant persons." "| mailx -s " "\"LDC_Snapshot_Status\" " b_n
}
}
close "NUM_CORR"
}
}

...

Regards!

...JRF...
Chris Frangandonis
Regular Advisor

Re: Reading two files with awk

Hi James ,

Thanks , have done

Regards
Chris