|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Grepping using -w and dashes (-)
I have a script to sort a list of arbitrary hosts and determine if they are supported by grepping them into a master supported list. I cut all the suffixes of the hosts in the arbitrary list, leaving the "short" hostname if you will, then grep -w them into the master list. For example:
hosta.something.com becomes hosta, and hosta is grepped with -w into the master list. The master list may return something like hosta.anything.internal.com which is fine because that's the suffix our supported list uses. However, there are some hosts on our list named hosta-1, hosta-1-10, hosta-b-svr and so forth. When I grep -w hosta it will return all those others because the grep is not delimited by a dash. This seems like a particularly difficult problem because if the arbitrary list DOES supply a hostname with a dash I still need to be able to grep that. I think this is an impossible situation but just thought I'd ask. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Maybe I'm missing something, but is there a reason that dropping the
-w and adding leading "whitespace" and a trailing dot would not work? Assuming that shortname holds the converted host name that you're searching for: Code:
#if pattern is expected any place other than the beginning of the line
grep "[ \t]${shortname}\." master_file
# if pattern is expected as first token on line:
grep "^${shortname}\." master_fileIf these won't do it, then please post a sample of your master file (with obvious names dummied out). |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing columns with dashes | Xterra | Shell Programming and Scripting | 14 | 07-07-2010 07:28 PM |
| AWK script to omit top characters with dashes | magikminox | Shell Programming and Scripting | 3 | 09-02-2008 12:42 PM |
| grep throws in dashes? | kingdbag | UNIX for Dummies Questions & Answers | 3 | 04-27-2007 04:18 PM |
| double dashes | systemsb | UNIX for Dummies Questions & Answers | 2 | 05-18-2006 10:41 AM |
| help removing dashes from social security number | Marcia P | UNIX for Dummies Questions & Answers | 2 | 02-28-2006 08:10 PM |
|
|