- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Search for a match in file2 (xml)
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
тАО04-14-2010 11:42 PM
тАО04-14-2010 11:42 PM
Search for a match in file2 (xml)
Hi All,
I am having a problem searching for a match from file2 (text) in file1 (xml), If found print line from file2 and append a "YES" at the end or else "NO"
I do get the results I want but that's if I remove the "
Script
gawk -v opt="
#RS = "
}
NR == FNR {
b[$1] = $0
next
}
{
e = ""
for (x in b) {
if (match($0,x)) {
e = "YESSSSSSSSSSSS"
}
}
print $0" "e
}' File1 File2
File1
=====
File2
=====
630642266 913308 V 505848 1132175
640719766 915817 V 0 0
630625666 621524 V 165478144 348066498
Result should look like this
630642266 913308 V 505848 1132175 YES
640719766 915817 V 0 0 NO
630625666 621524 V 165478144 348066498 YES
Many Thanks
Chris
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2010 02:45 AM
тАО04-15-2010 02:45 AM
Re: Search for a match in file2 (xml)
BEGIN {
#RS = "
}
NR == FNR {
b[$1] = $0
next
}
It appears you want to create the map by doing a getline in the BEGIN block. Then reset your delimiters for the second file.
Or pass in the first file as a parm and use getline to read only from that file.
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1358924
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2010 02:57 AM
тАО04-15-2010 02:57 AM
Re: Search for a match in file2 (xml)
Thanks,
My mistake is should read as follows
gawk 'BEGIN{
FS = "[><]"
}
FNR == NR{
b[$1]=$3;next
But still I cannot get expected results
Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2010 01:04 AM
тАО04-16-2010 01:04 AM
Re: Search for a match in file2 (xml)
no too subtle, what about :
FILENAME == "file1.xml" && $1 ~ /^
poid_tmp=substr(A[2],1,index(A[2],"<")) ;
poid[poid_tmp] = 1 ;
next ;
}
FILENAME == "file2.txt" {
if ( $1 in poid ) printf "%s YES\n",$0 ;
else printf "%s NO\n",$0 ;
}
whith appropriate name ?
Jean-Yves Picard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2010 07:37 PM
тАО04-20-2010 07:37 PM
Re: Search for a match in file2 (xml)
awk -v map=File1 '
BEGIN {
FS = "[><]"
while (getline < map > 0) {
if ($2 == "POID") {
# print "map:", $3
map_poid[$3] = $0
}
}
close(map)
FS = "[ \t]"
}
{
if (map_poid[$1] == "") result = "NO"
else result = "YES"
print $0, result
}' File2