- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Question about cat and grep commands with awk
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
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
07-28-2009 04:15 AM
07-28-2009 04:15 AM
Hi all,
I am trying to execute a command which takes the today's current date and performs a search in the syslog file. I was first trying with the followin commands with no success:
grep ""date |awk ' { print $2" "$3} '"" /var/adm/syslog/syslog.log
cat /var/adm/syslog/syslog.log | grep "date | awk ' { print $2" "$3 } '"
After a while I got what I was looking for by issuing the following command:
cat /var/adm/syslog/syslog.log | grep "`date | cut -c 5-10`"
Can anybody tell what is failing in the first two commands? And, does anybody know alternative ways to achieve the same thing bye other commands or methods?
Thanks all in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2009 04:32 AM
07-28-2009 04:32 AM
SolutionBy using the 'date' formatting directives you can get the short month name and space-filled day value consistent with what matches the 'syslog' format:
# grep "$(date '+%b %e')" /var/adm/syslog/syslog.log
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2009 05:31 AM
07-28-2009 05:31 AM
Re: Question about cat and grep commands with awk
Thx!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2009 05:34 AM
07-28-2009 05:34 AM
Re: Question about cat and grep commands with awk
%b Abbreviated month name. For example, Jan.
...
%d Day of the month as a two-digit decimal number [01-31].
You know, any flavor of unix has this wonderful utility called "man" used in conjunction with the command, which gives you the command usage manual. In your particular case, the magic command would be
# man date
please use the command liberally throughout your day.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2009 05:39 AM
07-28-2009 05:39 AM
Re: Question about cat and grep commands with awk
> Could you please explain why you used '+%b %e' ??
I did. This format directive yields the short month name and _space-filled_ day value consistent with what matches the 'syslog' format:
# date '+%b %e'
Jul 28
This is better than doing:
# date|cut -c5-10
...which requires a second process (the 'cut') to be spawned.
By the way, anytime you see 'grep' and 'awk' and/or 'cat' in a pipeline, remember that 'grep' and 'awk' can read input directly by specifying the file(s) on their command line. Too, 'awk' was designed to pattern match piping the output of 'grep' to it is generally another wasted process.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2009 07:04 AM
07-28-2009 07:04 AM
Re: Question about cat and grep commands with awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 01:09 AM
07-29-2009 01:09 AM