- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Easy points awk question
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
Forums
Discussions
Discussions
Discussions
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
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
02-18-2003 06:55 AM
02-18-2003 06:55 AM
Input file with one field (50,000+ lines)
compare each line to another file, if the $1 matches the first field of the 2nd input file(like a grep,but awk is faster), write that 2nd file line to another file(outfile) otherwise skip to the next record in file 1.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 07:05 AM
02-18-2003 07:05 AM
Re: Easy points awk question
How about 'comm':
# comm -3 file1 file2 > newfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 07:06 AM
02-18-2003 07:06 AM
Re: Easy points awk question
Ooops, I think you wanted the inverse:
# comm -12 file1 file2 > newfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 07:22 AM
02-18-2003 07:22 AM
Re: Easy points awk question
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 07:32 AM
02-18-2003 07:32 AM
Re: Easy points awk question
comm -3
comm -2
File one will always have one field and that one field will either be in file2 or not, if in file2 put it in file file
sample file1
abc@abc.om
def@def.com # will not be in file2
xyz@xyz.com
etc..
etc..
sampe file2
abc@abc.com abc123.xyz.net
xyz@xyz.com axz999.yahoo.com
etc..... etc.....
expected file3
abc@abc.om
xyz@xyz.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 07:37 AM
02-18-2003 07:37 AM
Re: Easy points awk question
Try:
join -1 1 -2 1 -o 2.1,2.2,2.3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 07:53 AM
02-18-2003 07:53 AM
Re: Easy points awk question
first file = file1
second file = file2
while read entry
do
/usr/bin/awk -v value=$entry '
$1==value {print $0}' file2
done < file1
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 07:54 AM
02-18-2003 07:54 AM
Re: Easy points awk question
I thought Leif had the answer. But as an example
abc@abc.com from file1 (master listing) was in file1 85 times, but using Leif it gave me a count of only four times.
And Jim, this is the first time that you have unable to provide the correct result the first response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 08:00 AM
02-18-2003 08:00 AM
Re: Easy points awk question
OK, when you said "line" I took you literally. Merijn (Procura) offered the better command. Try this:
# join -a2 file1 file2 > newfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 08:06 AM
02-18-2003 08:06 AM
Re: Easy points awk question
awk '
{
while (getline line < "file2") {
split (line, l);
if ($1 == l[1])
print ($1);
}
close ("file2");
}' < file1 > file3
If you need the complete "2nd file line" in the output, replace print ($1) with print (line).
Best regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 08:20 AM
02-18-2003 08:20 AM
Re: Easy points awk question
open(INP,"
close(INP);
while(<>) { chomp; print $lu{$key},"\n" if $lu{$key}; }
Run by entering-
perl aboveprogram.pl firstfile
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 08:27 AM
02-18-2003 08:27 AM
Re: Easy points awk question
On the last line of the perl program use "$_" instead of "$key".
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 08:28 AM
02-18-2003 08:28 AM
Re: Easy points awk question
The two files has to be sorted on the join fild before using "join".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 08:52 AM
02-18-2003 08:52 AM
Re: Easy points awk question
Try:
for unm in `awk -F: '{print $0}'
do
awk -v v1=$unm 'match($0,v1){print substr($0,RSTART,RLENGTH)}'
done
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 11:07 AM
02-18-2003 11:07 AM
Re: Easy points awk question
The join doesnt come even close to separating the files correctly, I sorted the two input files. I guess I will have to try to Perl option next.
But once again thanks for all the response and suggestions. I will assign points as soon as I double check my work and make sure I have had any finger checks on typing in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 11:24 AM
02-18-2003 11:24 AM
Re: Easy points awk question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 12:25 PM
02-18-2003 12:25 PM
Re: Easy points awk question
#!/bin/sh -xv
awk '
{
while (getline line < tmpusertable) {
split (line,l);
if($1 == l[1])
print ($1);
}
close (tmpusertable);
}' < work6 > work7
This way it runs 5 seconds and work7 is empty.
work6 has 24,000 lines and tmpusertable has 250,000 lines and I expect work7 to have about 18,000 lines.
If I put " " around tmpusertable like you have in the example it runs, but work7 is nothing but empty lines, I killed it after 32,000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 12:28 PM
02-18-2003 12:28 PM
Re: Easy points awk question
please try the attached semi-awk script, but first replace
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 12:28 PM
02-18-2003 12:28 PM
Re: Easy points awk question
I am not sure I have understand you correct but I used your example and added some lines to file1 (xxx in my test).
# cat xxx
abc@abc.com
def@def.com
xyz@xyz.com
abc@abc.com
abc@abc.com
abc@abc.com
abc@abc.com
#
# cat yyy
abc@abc.com abc123.xyz.net
xyz@xyz.com axz999.yahoo.com
# sort xxx >zzz
# join -1 1 -2 1 -o 2.1 zzz yyy
abc@abc.com
abc@abc.com
abc@abc.com
abc@abc.com
abc@abc.com
xyz@xyz.com
Of course yyy need to be sorted too but in the example this was already done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 12:34 PM
02-18-2003 12:34 PM
Re: Easy points awk question
File xxx is addresses coming in. File yyy has the incoming address and a possible forwarding addres.
Your lines of xxx always match something in yyy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 12:42 PM
02-18-2003 12:42 PM
Re: Easy points awk question
first file = file1 or index
second file = data
If file1 has multiple entries and if you do not want multiple entries to be printed out from file2, then you can just do one more step before running this script.
$sort file1 |uniq > index
#!/usr/bin/ksh
while read entry
do
/usr/bin/awk -v value=$entry '
$1==value {print $0}' data
done < index
If not, replace index in the above script with file1. The above script works for me. Simply copy and paste the script. Replace only data and index with your files.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 12:46 PM
02-18-2003 12:46 PM
Re: Easy points awk question
# perl -e '@ARGV=("file1");while(<>){chomp;$p{$_}++};@ARGV=("file2");while(<>){m/^(\S+)/&&exists$p{$1}and print}'
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 12:46 PM
02-18-2003 12:46 PM
Re: Easy points awk question
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 12:52 PM
02-18-2003 12:52 PM
Re: Easy points awk question
#!/bin/ksh -xv
# tmpusertable has 2 fields a incoming address
# and a forwarding address
#
# work6 has one field either a incoming address
# or a forwarding address.
# The results that I want is a output file that
# will only have incoming
# address that have matched up
# Sample work6 file next 2 lines
# xxx@aol.com # will generate a output line
# bbb@aol.com # will not generate a output line
#
# Sample tmpusertable next line
# xxx@aol.com yyy@yahoo.com
#
while read line
do
awk -v item=$line '{if ($1 != item ) continue; else print $1}' tmpusertable
done < work6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 12:56 PM
02-18-2003 12:56 PM