- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep issues
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
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
тАО03-22-2010 11:39 AM
тАО03-22-2010 11:39 AM
I'm having issues with the following grep statement:
#!/bin/sh
File1="/tmp/Myfile"
String="100% packet loss"
Control="/tmp/Control_file.txt"
/usr/bin/grep $String $File1 > $Control
Check=`/sbin/cat $Control | /usr/bin/wc -l`
.
.
.
With this I'm getting
grep: can't open packet
grep: can't open loss
When I run it directly from command line:
# String='100% packet loss'
# /usr/bin/grep $String $File1 > $Control
grep: can't open packet
grep: can't open loss
But if I do:
# /usr/bin/grep '100% packet loss' $File1 > $Control
#
... It works! So what I'm doing wrong?
Regards!
Solved! Go to Solution.
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 11:45 AM
тАО03-22-2010 11:45 AM
Re: grep issues
change to
String=\"100% packet loss\"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 11:57 AM
тАО03-22-2010 11:57 AM
Re: grep issues
This what I'm get:
# String=\"100% packet loss\"
sh: packet: not found.
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 12:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 12:49 PM
тАО03-22-2010 12:49 PM
Re: grep issues
As Patrick suggested, quote the '$String' variable. This prevents the shell from evaluating it before 'grep' does.
When you did:
# String="100% packet loss"
# /usr/bin/grep $String $File1 > $Control
...The shell expanded things to:
# /usr/bin/grep 100% packet loss /tmp/Myfile > /tmp/Control_file.txt
...which isn't a syntax that 'grep' understands :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 01:46 PM
тАО03-22-2010 01:46 PM
Re: grep issues
Thanks for the explanation James!.
Quoting did the trick.
Regards!