- 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 12:57 PM
02-18-2003 12:57 PM
Re: Easy points awk question
Again, sorry if I misunderstand you.
There is one line in the file xxx (or in the sorted zzz) which not matches anything in yyy:
def@def.com
But this line is not in the output from the join command in the example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 01:08 PM
02-18-2003 01:08 PM
Re: Easy points awk question
# 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 out line
# yyy@yahoo.com #Will also generate a out line
#
# Sample tmpusertable next line
# xxx@aol.com yyy@yahoo.com
I ran your join again, I had one line I know had 15 entries but your solution only put 5 lines in the outputfile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 01:19 PM
02-18-2003 01:19 PM
Re: Easy points awk question
Here is the attached session file using my awk script.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 01:44 PM
02-18-2003 01:44 PM
Re: Easy points awk question
Perhaps I understand you better now.
You want to match the lines in file1 on both fields in file2.
If using join you have to do this in two steps.
The sorted lines of file2 must be uniq.
Example:
sort file1 >xxx
sort file2 |uniq >yyy
join -1 1 -2 1 -o 2.1 xxx yyy
sort file2 -k 2 |uniq >yyy
join -1 1 -2 2 -o 2.2 xxx yyy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 01:46 PM
02-18-2003 01:46 PM
Re: Easy points awk question
For you brave hearts that want to continue I have added an attachement trying to explain the infile1 to compare against a MasterDB file and the resulting output file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 02:05 PM
02-18-2003 02:05 PM
Re: Easy points awk question
open(INP,"
chomp;
($addr1,$addr2)=split(" ",$_);
$lu{$addr1}=$addr1; $lu{$addr2}=$addr1}
}
close(INP);
while(<>) { chomp; print $lu{$_},"\n" if $lu{$_}; }
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2003 02:12 PM
02-18-2003 02:12 PM
Re: Easy points awk question
With the latest input you provide, here is the modified script again.
while read entry
do
/usr/bin/awk -v value=$entry '
$1 == value || $2 == value {print $1}' data
done < index
here
data = your database
index = inputfile1
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 01:03 AM
02-19-2003 01:03 AM
Re: Easy points awk question
I checked your example, I assume (example)
"5.mop@yahoo.com" should be "mop@yahoo.com"
and
devio.excite.com should be devio@excite.com
There is a mix of space and tab characters as delimiter in file2 so I need to do some processing first. I create temporary files so the original is unchanged. It seems as it does no sense if the matching is on field 1 or two so I create a temporary file with only one field and have to match only once.
Script:
cat file2 |tr "\040" "\011" |tr -s "\011" >yyy
cut -f 1 yyy >zzz
cut -f 2 yyy >>zzz
sort file1 >xxx
sort zzz |uniq >yyy
join -1 1 -2 1 xxx yyy
Result:
abc12@excite.com
abc@yahoo.com
abc@yahoo.com
def@excite.com
devio@excite.com
jaim@yalei.net
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 02:28 AM
02-19-2003 02:28 AM
Re: Easy points awk question
awk '
{
while (getline line < "masterdb") {
if ($1 != "" && line != "" && match (line, $1) && split (line,l))
print (l[1]);
}
close ("masterdb");
}' < infile > outfile
BTW, the doublequotes (") are important.
$cat infile
abc@yahoo.com
def@excite.com
999@nosite.net
jaim@yalei.net
abc12@excite.com
devio@excite.com
abc@yahoo.com
texas_tiger.net
$cat masterdb
abc@yahoo.com def@hotmail.com
def@excite.com 12345@yahoo.edu
dyd@hotmail.com jaim@yalei.net
abc12@excite.com pepso@usa.gov
mop@yahoo.com devio@excite.com
rxyte@yahoo.com zyzzz@cox.net
$cat outfile
abc@yahoo.com
def@excite.com
dyd@hotmail.com
abc12@excite.com
mop@yahoo.com
abc@yahoo.com
Hopefully this works now. However, this is supposed to work with unsorted files without doing hundreds of thousends fork/exec's.
Regards...
Dietmar, learning a lot during this threads. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 02:41 AM
02-19-2003 02:41 AM
Re: Easy points awk question
here my 2ct.:
awk -vmaster=MASTERFILE 'BEGIN{n=0;
while(getline < master)
{
master1[n]=$1
master2[n++]=$2
}
close(master);
}
{
for(i=0;i
if($1 == master1[i] || $1 == master2[i])
{
print master1[i];
break;
}
}
}' FILE
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 04:38 AM
02-19-2003 04:38 AM
Re: Easy points awk question
please try the attached script, using the nightly logfile as par1 and the database file as par2.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 06:35 AM
02-19-2003 06:35 AM
Re: Easy points awk question
awk ' { for ( i=1; i<= NF; i++ ) print $i }' master > all_masters
awk ' { for ( i=2; i<= NF; i++ ) print "s/"$i"/"$1"/" }' master > sed_masters
awk '{ print NR, $1 }' in > numbered_in
grep -f all_masters numbered_in > founds
sed -f sed_masters founds > thats_all_folks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 08:32 AM
02-19-2003 08:32 AM
Re: Easy points awk question
John Korterman, I appreciate all your time and efforts, but I have cut and pasted your script twice, have saved it and shuttled it to my system ran dos2unix on it and I still get a syntax error bailout on line 1. I have tried it on a Sun platform and a HP platform with the same results. I have subsituted my files for $1 and $2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 08:38 AM
02-19-2003 08:38 AM
Re: Easy points awk question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 08:43 AM
02-19-2003 08:43 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-19-2003 08:52 AM
02-19-2003 08:52 AM
Re: Easy points awk question
Maybe tomorrow i will write a better script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 08:54 AM
02-19-2003 08:54 AM
Re: Easy points awk question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 09:15 AM
02-19-2003 09:15 AM
Re: Easy points awk question
Did you try my latest little orthodox awk script?. I used the sample data and index given by you and it prints exactly what you mentioned.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 09:25 AM
02-19-2003 09:25 AM
Re: Easy points awk question
I'm sorry to hear that it bails out in line one - I just cut and pasted my lastly attached script and ran it like this:
# ./copied.sh ./fil1 ./fil2
and it produced this output:
abc@yahoo.com
def@excite.com
abc12@excite.com
abc@yahoo.com
dyd@hotmail.com
mop@yahoo.com
My script is made by the crudest of tools: hand-crafted in vi, the bail out error from awk indicates that something has gone wrong in the copy/paste/dos2unix operations. Perhaps you could try to type it in manually in vi, maybe just rewrite the first awk line to see if the error messages "moves".
Or attach your input and let me run the script - could be arranged for a few beers.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 09:43 AM
02-19-2003 09:43 AM
Re: Easy points awk question
For Carlos, I do have three awk books and I did read and I am not a programmer, I have over 75 written scripts that make my daily jobs easier and they have a lot of basic awk statements but this situation was different and grepping was really to slow.
So once again thank you all for your time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 09:58 AM
02-19-2003 09:58 AM
SolutionHave you problems running awk scripts on Sun (and if running an older version of Solaris), try nawk instead, it should be compatible with awk on HPUX.
In my example I missed that you wanted the first field outpyt if the matching was on the second field. The example below should work better.
cat file2 |tr "\040" "\011" |tr -s "\011" >yyy
sort file1 >xxx
sort -k 1 yyy >zzz
join -1 1 -2 1 -o 1.1 xxx zzz
sort -k 2 yyy >zzz
join -1 1 -2 2 -o 2.1 xxx zzz
#
# ./testj
abc12@excite.com
abc@yahoo.com
abc@yahoo.com
def@excite.com
mop@yahoo.com
dyd@hotmail.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 10:15 AM
02-19-2003 10:15 AM
Re: Easy points awk question
Here is the result of my session-
$ cat masterdb
abc@yahoo.com def@hotmail.com
def@excite.com 12345@yahoo.edu
dyd@hotmail.com jaim@yalei.net
abc12@excite.com pepso@usa.gov
mop@yahoo.com devio.excite.com
rxyte@yahoo.com zyzzz.cox.net
$
$ cat infile1
abc@yahoo.com
def@excite.com
999@nosite.net
jaim@yalei.net
abc12@excite.com
devio@excite.com
abc@yahoo.com
texas_tiger.net
$
$ cat myreport.pl
open(INP,"
chomp;
($addr1,$addr2)=split(" ",$_);
$lu{$addr1}=$addr1; $lu{$addr2}=$addr1;
}
close(INP);
while(<>) { chomp; print $lu{$_},"\n" if $lu{$_}; }
$
$ perl myreport.pl infile1
abc@yahoo.com
def@excite.com
dyd@hotmail.com
abc12@excite.com
abc@yahoo.com
The results are what you stated in your sample. This perl script should also be a lot more effecient then any of the awk or sed scripts.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2003 11:17 AM
02-19-2003 11:17 AM
Re: Easy points awk question
Thank you so very much -- Plus all you other guys who put up with this stubborn old man.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2003 07:47 AM
02-20-2003 07:47 AM
Re: Easy points awk question
Thanks all once again....
- « Previous
-
- 1
- 2
- Next »