- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Can AWK read two files
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
тАО05-06-2005 02:08 AM
тАО05-06-2005 02:08 AM
Can AWK read two files
Is there a way in which AWK reads two files, get a result from each file, and then subtracts file1 result from file2 result.
e.g.
x=/= "RM_[0-9][0-9][0-9][0-9][0-9]/{print substr($3,2,10),substr($3,7,5) | "tail -n1"}' from file1
y={if($1~/^IP/ && $9~/M_[0-9]/){print substr($9,1,10),substr($9,6,5)|"sort -u"}}' from file2
res=(x[2]-y[2])
then
{if(res ==3) {----> here we call a system call
}
else {if(res == 2)
{----> here we call a system call}
}
}
}
My x values is "Jack_00212 00212"
y values is "Jack_00210 00210"
Many Thanks
Chris
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2005 02:38 AM
тАО05-06-2005 02:38 AM
Re: Can AWK read two files
I usually feed data into awk.
Surely you can run do this:
$result1=(
$result2=(
Then you can compare (subtract) the values in result1 and result2 variables.
You could also redirect the output to files and use the diff command to compare the results.
awk is merely a tool here. I don't think it can do the job itself, the job will get done with some thoughtful script design.
I'd try and break it into smaller chunks.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2005 02:44 AM
тАО05-06-2005 02:44 AM
Re: Can AWK read two files
Thanks for your reply. Yes it was my initial plan, but I thought, why not learn from asking. I have seen AWK scripts doing this kind of method.
Many thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2005 05:11 AM
тАО05-06-2005 05:11 AM
Re: Can AWK read two files
Perl could do it, or consider sed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2005 06:10 AM
тАО05-06-2005 06:10 AM
Re: Can AWK read two files
cat file2 | sort -u | awk '
BEGIN {
while ( getline var file1 > 0 )
if ( var ~ /pattern1/ ) {
x=substr();
}
}}
/pattern2/ {
y=substr();
res= x - y;
if ( res ==2 ) ...
if ( res ==3 ) ...
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2005 09:00 PM
тАО05-06-2005 09:00 PM
Re: Can AWK read two files
Thanks. The only problem is that after the pattern search in both files, I only require the last line for both cases. Only then will I be able to subtract "x-y" and then use result in a "if" loop.
Scot,
My Perl knowledge is about 30%.
Many Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-07-2005 01:52 AM
тАО05-07-2005 01:52 AM
Re: Can AWK read two files
cat file2 | sort -u | awk '
BEGIN {
while ( getline var file1 > 0 )
if ( var ~ /pattern1/ ) {
x=substr();
}
}
/pattern2/ {
y=substr();
}
END {
res= x - y;
if ( res ==2 ) ...
if ( res ==3 ) ...
)