LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Issue trying to grep a string, but keep a similar string (https://www.linuxquestions.org/questions/linux-software-2/issue-trying-to-grep-a-string-but-keep-a-similar-string-906220/)

Supp0rtLinux 10-03-2011 01:26 PM

Issue trying to grep a string, but keep a similar string
 
I have a output string that looks like this:

hp31408804325.ir.cs.domain.edu 21.23 GB
ilmn-pipeline.ir.cs.domain.edu 38.73 GB
imhotep 0 kb
imhotep.ir.cs.domain.edu 164.10 GB
ipcam.ir.cs.domain.edu 8477.25 GB
ishtar-backups.ir.cs.domain.edu 125204.38 GB

I need to grep out (ie: "grep -v ..."or "egrep -v ...") the string "imhotep" above, but retain the longer string "imhotep.ir.cs.domain.edu".

Specifically, this relates to our backup software. At one point, a previous admin had setup the hosts by their short name. This was later changed to FQDN names, however our reports are still showing the short name due to some "never expire" archive policies. I want to remove the short name entry as its not relevant to our reports, but keep the long name. This would be trivial if I were doing it the other way around, but I can't figure out how to grep out the short name yet retain the longer name. Any thoughts?

Tinkster 10-03-2011 02:19 PM

Quote:

Originally Posted by Supp0rtLinux (Post 4488994)
I have a output string that looks like this:

hp31408804325.ir.cs.domain.edu 21.23 GB
ilmn-pipeline.ir.cs.domain.edu 38.73 GB
imhotep 0 kb
imhotep.ir.cs.domain.edu 164.10 GB
ipcam.ir.cs.domain.edu 8477.25 GB
ishtar-backups.ir.cs.domain.edu 125204.38 GB

I need to grep out (ie: "grep -v ..."or "egrep -v ...") the string "imhotep" above, but retain the longer string "imhotep.ir.cs.domain.edu".

Specifically, this relates to our backup software. At one point, a previous admin had setup the hosts by their short name. This was later changed to FQDN names, however our reports are still showing the short name due to some "never expire" archive policies. I want to remove the short name entry as its not relevant to our reports, but keep the long name. This would be trivial if I were doing it the other way around, but I can't figure out how to grep out the short name yet retain the longer name. Any thoughts?

Code:

echo "hp31408804325.ir.cs.domain.edu          21.23 GB
> ilmn-pipeline.ir.cs.domain.edu          38.73 GB
> imhotep                                      0 kb
> imhotep.ir.cs.domain.edu                164.10 GB
> ipcam.ir.cs.domain.edu                  8477.25 GB
> ishtar-backups.ir.cs.domain.edu        125204.38 GB" | egrep -v '^[^.]+ '
hp31408804325.ir.cs.domain.edu          21.23 GB
ilmn-pipeline.ir.cs.domain.edu          38.73 GB
imhotep.ir.cs.domain.edu                164.10 GB
ipcam.ir.cs.domain.edu                  8477.25 GB
ishtar-backups.ir.cs.domain.edu        125204.38 GB

In English: suppress anything that doesn't have a PERIOD in the
first word of a line.

Cheers,
Tink

Supp0rtLinux 10-03-2011 04:20 PM

Great suggestion, but it doesn't seem to work:

bash-3.00# echo "imhotep" | egrep -v '^[^.]+ '
imhotep

FYI: I'm on Solaris 10... not sure if this is relevant.

Tinkster 10-03-2011 06:39 PM

Quote:

Originally Posted by Supp0rtLinux (Post 4489105)
Great suggestion, but it doesn't seem to work:

bash-3.00# echo "imhotep" | egrep -v '^[^.]+ '
imhotep

FYI: I'm on Solaris 10... not sure if this is relevant.

No, the problem in this case is not w/ slowarse as I lovingly
call it, neither with its geriatric toolset; it's w/ the regex,
or rather the input you're throwing it: it doesn't resemble what
you told us you're looking for, there's no trailing whitespace
in "imhotep", hence the regex won't take. If you tried
Code:

echo "imhotep " | egrep -v '^[^.]+ '
you wouldn't get output.


Cheers,
Tink

Supp0rtLinux 10-04-2011 08:19 AM

Thanks for the clarification. I guess my snippet of data didn't properly reflect the environment. In the case of only having hostnames (and no trailing whitespace - see example below):

hp31408804325.ir.cs.domain.edu
ilmn-pipeline.ir.cs.domain.edu
imhotep
imhotep.ir.cs.domain.edu
ipcam.ir.cs.domain.edu
ishtar-backups.ir.cs.domain.edu

How would I grep out the short hostname "imhotep", but keep the FQDN hostname "imhotep.ir.cs.domain.edu"?

Tinkster 10-04-2011 02:09 PM

almost the same:
Code:

echo "hp31408804325.ir.cs.domain.edu
> ilmn-pipeline.ir.cs.domain.edu
> imhotep
> imhotep.ir.cs.domain.edu
> ipcam.ir.cs.domain.edu
> ishtar-backups.ir.cs.domain.edu
> "|egrep -v '^[^.]+$'
hp31408804325.ir.cs.domain.edu
ilmn-pipeline.ir.cs.domain.edu
imhotep.ir.cs.domain.edu
ipcam.ir.cs.domain.edu
ishtar-backups.ir.cs.domain.edu


Supp0rtLinux 10-04-2011 04:15 PM

Thanks... that did the trick

Tinkster 10-04-2011 06:35 PM

Welcome. You get the difference between the regexes, and why
which one works with which data set?


Cheers,
Tink


All times are GMT -5. The time now is 07:59 AM.