LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 10-03-2011, 01:26 PM   #1
Supp0rtLinux
Member
 
Registered: Dec 2001
Location: Carlsbad
Distribution: LFS 4.0 (www.linuxfromscratch.org)
Posts: 44

Rep: Reputation: 15
Question 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?

Last edited by Supp0rtLinux; 10-03-2011 at 02:00 PM.
 
Old 10-03-2011, 02:19 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Quote:
Originally Posted by Supp0rtLinux View Post
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

Last edited by Tinkster; 10-03-2011 at 02:21 PM.
 
Old 10-03-2011, 04:20 PM   #3
Supp0rtLinux
Member
 
Registered: Dec 2001
Location: Carlsbad
Distribution: LFS 4.0 (www.linuxfromscratch.org)
Posts: 44

Original Poster
Rep: Reputation: 15
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.
 
Old 10-03-2011, 06:39 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Quote:
Originally Posted by Supp0rtLinux View Post
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
 
Old 10-04-2011, 08:19 AM   #5
Supp0rtLinux
Member
 
Registered: Dec 2001
Location: Carlsbad
Distribution: LFS 4.0 (www.linuxfromscratch.org)
Posts: 44

Original Poster
Rep: Reputation: 15
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"?
 
Old 10-04-2011, 02:09 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
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
 
1 members found this post helpful.
Old 10-04-2011, 04:15 PM   #7
Supp0rtLinux
Member
 
Registered: Dec 2001
Location: Carlsbad
Distribution: LFS 4.0 (www.linuxfromscratch.org)
Posts: 44

Original Poster
Rep: Reputation: 15
Thanks... that did the trick
 
Old 10-04-2011, 06:35 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

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


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] copy string a to string b and change string b with toupper() and count the chars beep3r Programming 3 10-22-2010 07:22 PM
grep not getting whole string bic Programming 4 08-23-2010 12:07 PM
[SOLVED] How to GREP string? tquang Linux - General 2 07-30-2010 12:51 AM
grep a particular string john83reuben Linux - Newbie 3 12-07-2009 09:34 AM
grep string with space (2 word string) casperdaghost Linux - Newbie 7 08-24-2009 02:11 AM


All times are GMT -5. The time now is 07:26 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration