- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep and strings with 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
Discussions
Discussions
Discussions
Forums
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
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
тАО04-25-2008 02:06 PM
тАО04-25-2008 02:06 PM
i have:
a=`date "+%b %d"`
echo $a = "Apr 25"
if i run:
cat log | grep $a
$ cat log | grep $a
grep: can't open 25
how can i fix it ..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-25-2008 02:09 PM
тАО04-25-2008 02:09 PM
Re: grep and strings with spaces
cat log | grep "$a"
├В┬┐?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-25-2008 02:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-25-2008 02:31 PM
тАО04-25-2008 02:31 PM
Re: grep and strings with spaces
grep Apr 25
so it would search Apr and not "Apr 25"
that is why this error.
Hope u got it.
BR,
Kapil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-25-2008 06:15 PM
тАО04-25-2008 06:15 PM
Re: grep and strings with spaces
month=`date +%b`
day=`date +%d`
echo $month' '$day
grep "$month' '$day" syslog.log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-25-2008 06:18 PM
тАО04-25-2008 06:18 PM
Re: grep and strings with spaces
month=`date +%b`
day=`date +%d`
echo $month'BB'$day
grep "$month'BB'$day" syslog.log
Note: BB means 2 x space.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2008 03:56 AM
тАО04-26-2008 03:56 AM
Re: grep and strings with spaces
You need to quote the variable:
# grep "$a" log
...so that the shell doesn't expand the variable into "
# grep Apr 25 log
...before 'grep' sees it.
That said, do NOT spawn an extra process (the 'cat') merely to read the file and pipe it to 'grep' which is only going to read (again!) the output of the pipe. Many standard Unix utilities are written to consider the final arguments as files to be read. In fact, the error 'grep: can't open 25' in the case above, is 'grep' telling you that it can't find what it thinks is a file named "25".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2008 02:43 PM
тАО04-26-2008 02:43 PM
Re: grep and strings with spaces
There is a box "Retain format" you can check keep the spaces, " ".