Sponsored Content
Top Forums Shell Programming and Scripting Using grep returns partial matches, I need to get an exact match or nothing Post 302490620 by ec01 on Tuesday 25th of January 2011 10:01:31 AM
Old 01-25-2011
alternative solution using awk and/or nawk to match the exact zoneName:
Code:
# cat /var/tmp/zoneadm.out.test
  ID NAME             STATUS     PATH                           BRAND    IP
   0 global           running    /                              native   shared
   1 myzone1          running    /zones/myzone1                 native   shared
   2 myzone1-old      running    /zones/myzone1-old             native   shared
   4 myzone2          running    /zones/myzone2                 native   shared
   5 myzone2-old      running    /zones/myzone2-old             native   shared
   6 myzone2-another  running    /zones/myzone2-another         native   shared
   7 myzone2-junk     running    /zones/myzone2-junk            native   shared
# zoneName=myzone2
# awk '$2 == "'$zoneName'"' /var/tmp/zoneadm.out.test
   4 myzone2          running    /zones/myzone2                 native   shared
# zoneName=myzone2-
# awk '$2 == "'$zoneName'"' /var/tmp/zoneadm.out.test  ### no match
# zoneName=myzone2-old
# awk '$2 == "'$zoneName'"' /var/tmp/zoneadm.out.test
   5 myzone2-old      running    /zones/myzone2-old             native   shared

(in your case you'd run zoneadm list -vic then pipe it to awk instead rather than using the file)

Be careful with the quotes for the shell variables (ie: quote as exactly as shown). nawk may be easier if the quotes are too hard to read:
Code:
# zoneName=myzone2
# nawk -v zonename=${zoneName} '$2 == zonename {print $2}' /var/tmp/zoneadm.out.test
myzone2


Last edited by ec01; 01-25-2011 at 11:01 AM.. Reason: fix code tags
This User Gave Thanks to ec01 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Exact Match thru grep ?????

hey..... i do have text where the contents are like as follows, FILE_TYPE_NUM_01=FILE_TYPE=01|FILE_DESC=Periodic|FILE_SCHDL_TYPE=Daily|FILE_SCHDL=|FILE_SCHDL_TIME=9:00am|RESULTS=B FILE_TYPE_NUM_02=FILE_TYPE=02|FILE_DESC=NCTO|FILE_SCHDL_TYPE=Daily|FILE_SCHDL=|FILE_SCHDL_TIME=9:00am|RESULTS=M... (2 Replies)
Discussion started by: manas_ranjan
2 Replies

2. Shell Programming and Scripting

find/grep returns no matches

Hi all! I've faced with very unintelligible error using find/grep like this: root@v29221:~# find /var/www/igor/data/www/lestnitsa.ru | grep u28507I get nothing as a result, but: root@v29221:~# grep u28507 /var/www/igor/data/www/lestnitsa.ru/_var.inc $db_name = 'u28507';... (2 Replies)
Discussion started by: ulrith
2 Replies

3. Solaris

grep exact match

Hi This time I'm trying to grep for an exact match e.g cat.dog.horse.cow.bird.pig horse.dog.pig pig.cat.horse.dog horse dog dog pig.dog pig.dog.bird how do I grep for dog only so that a wc -l would result 2 in above case. Thanks in advance ---------- Post updated at 06:33 AM... (4 Replies)
Discussion started by: rob171171
4 Replies

4. UNIX for Dummies Questions & Answers

grep and sed exact match questions

This was mistaken as homework in a different forum, but is not. These are questions that are close to what I am trying to do at work. QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1... (1 Reply)
Discussion started by: thibodc
1 Replies

5. Shell Programming and Scripting

Grep two words with exact match

HI Input : Counters Counter Int Ints Counters Counters Ints Ints I want to grep Counter|Int Output : Counter (1 Reply)
Discussion started by: pareshkp
1 Replies

6. Shell Programming and Scripting

Searching for exact match using grep

I am searching for an exact match on a value read from another file to lookup an email address in another file. The file being checked is called "contacts" and it has Act #, email address, and contact person. 1693;abc1693@yahoo.comt;Tommy D 6423;abc6423@yahoo.comt;Jim Doran... (2 Replies)
Discussion started by: ziggy6
2 Replies

7. Shell Programming and Scripting

Grep exact match

Hello! I have 2 files named tacs.tmp and tacDB.txt tacs.tmp looks like this 0 10235647 102700 106800 107200 1105700 tacDB.txt looks like this 100100,Mitsubishi,G410,Handheld,,0,0,0 100200,Siemens,A53,Handheld,,0,0,0 100300,Sony Ericsson,TBD (AAB-1880030-BV),Handheld,,0,0,0... (2 Replies)
Discussion started by: Cludgie
2 Replies

8. Shell Programming and Scripting

Grep -w not printing exact matches

Dear All, Here is my input TAACGCACTTGCGGCCCCGGGATAAAAAAAAAAAAAAAAAAAAATGGATT NAGAGGGACGGCCGGGGGCATAAAAAAAAAAAAAAAAAAAAAGGGATTTC NGGGTTTTAAGCAGGAGGTGTCAAAAAAAAAAAAAAAAAAAAAGGGATTT NTGGAACCTGGCGCTAGACCAAAAAAAAAAAAAAAAAAAATGGATTTTTG ATACTTACCTGGCAGGGGAGATACCATGATCAATAAAAAAAAAAAAAAAA... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

9. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. Shell Programming and Scripting

Grep for an exact match in a file

I am currently having some issues while trying to grep for a exact string inside a file. I have tried doing this from command line and things work fine i.e. when no match is found, return code=1 but when its done as part of my script it returns 0 for the same command - I dont know if there is an... (6 Replies)
Discussion started by: Ads89
6 Replies
native(5)						Standards, Environments, and Macros						 native(5)

NAME
native - native branded zone DESCRIPTION
The native brand uses the branded zones framework described in brands(5) to run zones installed with the same software as is installed in the global zone. The system software must always be in sync with the global zone when using a native brand. SUB-COMMANDS The following native brand-specific subcommand options are supported in zoneadm(1M). attach [-u] [-b patchid]... For native zones, zoneadm checks package and patch levels on the machine to which the zone is to be attached. If the packages/patches that the zone depends on from the global zone are different (have different revision numbers) from the dependent packages/patches on the source machine, zoneadm reports these conflicts and does not perform the attach. If the destination system has only newer dependent packages/patches (higher revision numbers) than those on the source system, you can use the -u option to update the attached zone to match the -revision packages and patches that exist on the new system. With -u, as in the default behavior, zoneadm does not perform an attach if outdated packages/patches are found on the target system. For native zones, one or more -b options can be used to specify a patch ID for a patch installed in the zone. These patches will be backed out before the zone is attached or, if -u was also specified, updated. install [-a archive] | [-d path] [-p] [-s] [-u] [-v] [-b patchid]... The native brand installer supports installing the zone from either the software already installed on the system or from an image of an installed system running the same release. This can be a full flash archive (see flash_archive(4)) or a cpio(1) or pax(1) "xustar" ar- chive. The cpio archive be compressed with gzip or bzip2. The image can also be a level 0 ufsdump(1M), a path to the top-level of a system's root tree, or a pre-existing zone path. With no options the zone is installed using same software as is running the global zone. To install the zone from a system image either the -a or -d is required. Either the -u or -p option is also required in this case. -a archive The path to a flash_archive(4), cpio(1), or pax(1) "xustar" archive, or a level0 ufsdump(1M), of an installed system. cpio archives may be compressed using gzip or bzip2. -b patchid One or more -b options can be used to specify a patch ID for a patch installed in the system image. These patches will be backed out during the installation process. -d path The path to the root directory of an installed system. If path is a hyphen (-), the zonepath is presumed to be already populated with the system image. -p Preserve the system configuration after installing the zone. -s Install silently. -u Run sys-unconfig(1M) on the zone after installing it. -v Verbose output from the install process. ATTRIBUTES
See attributes(5) for a description of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWzoneu | +-----------------------------+-----------------------------+ |Interface Stability |Uncommitted | +-----------------------------+-----------------------------+ SEE ALSO
cpio(1), pax(1), zlogin(1), zonename(1), sys-unconfig(1M), ufsdump(1M), zoneadm(1M), zonecfg(1M), flash_archive(4), attributes(5), brands(5), privileges(5), zones(5), lx_systrace(7D) SunOS 5.11 13 Feb 2009 native(5)
All times are GMT -4. The time now is 08:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy