The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep for "exact word" bullz26 Shell Programming and Scripting 7 03-14-2008 05:00 AM
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 03:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
How to find out the exact year in "Last modified time" using ls command Dophlinne UNIX for Dummies Questions & Answers 6 04-11-2006 12:07 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-14-2009
farphe farphe is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 4
can awk built-in "match" be exact??

hello everybody,

as explained in the title, here is what I want:

str1="name1 name2 name3"
str2="name1"
str3="name"

I know that match(str1,str2) will return 1, but I want that match(str1,str3) returns 0 (when it also returns 1...)

Is there a way to get that exact matching process done in a awk script??

cheers,
Tanguy
  #2 (permalink)  
Old 01-14-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
What do you mean by "exact"? str2 and str3 are both found in str1, but neither is an exact match.
  #3 (permalink)  
Old 01-14-2009
farphe farphe is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 4
good point otheus...

well by that I mean that I'd like to compare each "field" of str1 (all fields being separated by a coma) and test if they match str3 (exactly). So basically I want to compare name1 to name, then name2 to name, then name3 to name... and check if they are exactly the same (in which case name1 compared to name is a false)

hum... not so clear, is it?
But maybe I'm simply not doing things the easier way...
  #4 (permalink)  
Old 01-14-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
It's clear now. Can you use "nawk" or GNU awk (gawk)?
  #5 (permalink)  
Old 01-14-2009
farphe farphe is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 4
yes I can use gawk if it makes things easier
  #6 (permalink)  
Old 01-14-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
First, use the split() function to split up the "str1" into an array. Then, search the array using "==". So:
Code:
split(str1,ary,",");
for (s in ary) 
  if (s == str2 || s == str3) { found=s; break; }
print found
  #7 (permalink)  
Old 01-14-2009
farphe farphe is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 4
excellent!

I had already tried that "split" thing in a couple of less elegant ways and with no success, so many thanks for that ;-)
Closed Thread

Bookmarks

Tags
awk match

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0