- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Reading two files with awk
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2008 08:29 AM
тАО11-27-2008 08:29 AM
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
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2008 09:13 AM
тАО11-27-2008 09:13 AM
SolutionThere 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...
- Tags:
- getline
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2008 09:23 AM
тАО11-27-2008 09:23 AM
Re: Reading two files with awk
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2008 09:44 AM
тАО11-27-2008 09:44 AM
Re: Reading two files with awk
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2008 09:56 AM
тАО11-27-2008 09:56 AM
Re: Reading two files with awk
Thanks , have done
Regards
Chris