- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script help - grep for string with embedded spaces
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 02:52 AM
12-10-2003 02:52 AM
blank=" "
match_string="$(date "+%b") $blank $(date "+%e") $(date "+%H")"
(I am not sure yet if $blank is working; when I concatenate the three portions of the date fields I need a space between the month and day of the month).
Currently $match_string = "Dec 10 09", so this looks good so far.
I now want to grep auth.log for lines that match this string. But I cannot seem to get a command that looks at the entire match string as one field. I have tried:
#grep $match_string /var/adm/syslog/auth.log
grep: can't open 10
grep: can't open 09
This is followed by listing all "Dec" entries.
I have also tried:
grep "$match_string" /var/adm/syslog/auth.log
gives me no results at all.
What should be captured by the grep would (for example) be:
Dec 10 09:55:03 sshd[10843]: Accepted password...
Dec 10 09:55:03 su: + ...
Any help would be appreciated.
Scott Lindstrom
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 02:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 03:02 AM
12-10-2003 03:02 AM
Re: Script help - grep for string with embedded spaces
Try this:
match_string=$(date +"%b %e %H")
grep "$match_string" /var/adm/syslog/auth.log
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 03:03 AM
12-10-2003 03:03 AM
Re: Script help - grep for string with embedded spaces
I had tried that and got no results.
But now that I look back, I had no entries for the hour in the match string!
I was so caught up in looking for a valid syntax, that I forgot to look for the obvious reason.
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 03:04 AM
12-10-2003 03:04 AM
Re: Script help - grep for string with embedded spaces
one should read all the email and not answer to quickly. ;-)
Try grep -i. Sometimes I get results with that. It should work, like you tried.
Is auth.log an ascii file?
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 03:06 AM
12-10-2003 03:06 AM
Re: Script help - grep for string with embedded spaces
blank="\ "
match_string="$(date "+%b")$blank$(date "+%e")$blank$(date "+%H")"
grep "$match_string" /var/adm/syslog/auth.log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 03:08 AM
12-10-2003 03:08 AM
Re: Script help - grep for string with embedded spaces
match_string="$(date "+%b") $blank $(date "+%e") $(date "+%H")"
should be:
match_string="$(date '+%b') $(date '+%e') $(date '+%H')"
then
grep "${match_string}" filename should work just fine.
I would do this first so that you can see exactly what ${match_string is set to -- it's difficult to know if you have spaces or tabs just wiewing your posting because of the way HTML handles whitespace.
echo "Match_string = \"${match_string}\""
When you get the spaces to exactly match what is in your file then grep should work like a charm iff you double quote the expression to match so that the variable is expanded AND passed as one argument to grep.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 03:17 AM
12-10-2003 03:17 AM
Re: Script help - grep for string with embedded spaces
match_string=$(date +"%b %e %H") works great (given that today is day 10).
Clay -
The reason that the space seemed to be an issue is yesterday's auth.log entries look like:
Dec 9 15:15:04
Today's auth.log entries look like:
Dec 10 07:07:04
Even though I understand %e is supposed to return the day of the month with a leading space, when I tried it with the three fields concatenated, I was getting "Dec 9 15" instead of "Dec 9 15". I may have to find a system in which I can set the date back to try this some more today.
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 03:31 AM
12-10-2003 03:31 AM
Re: Script help - grep for string with embedded spaces
Dec 9 15:15:04
should have two spaces between Dec and 9.
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 04:00 AM
12-10-2003 04:00 AM
Re: Script help - grep for string with embedded spaces
I tried:
blank="\ "
print $blank
and get back \ as the value of $blank.
Am I missing something here?
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 04:04 AM
12-10-2003 04:04 AM
Re: Script help - grep for string with embedded spaces
are you still having trouble?
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 04:06 AM
12-10-2003 04:06 AM
Re: Script help - grep for string with embedded spaces
e.g.
typeset -R2 MDAY=$(date '+%e')
match_string="$(date '+%b') ${MDAY} $(date '+%H')"
and will right justify to 2 positions and fill with leading spaces regardless if the day is a one or two digit value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2003 04:18 AM
12-10-2003 04:18 AM
Re: Script help - grep for string with embedded spaces
Still working my way thru testing the various replies. Things are looking very good. (I think I may be all set, but not 100% sure).
These forums are great! Getting so many valuable replies that I am behind in trying them is a great situation to be in!
Scott