- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: using grep in script
Categories
Company
Local Language
Forums
Discussions
- Integrity Servers
- Server Clustering
- HPE NonStop Compute
- HPE Apollo Systems
- High Performance Computing
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Knowledge Base
Forums
Discussions
- Cloud Mentoring and Education
- Software - General
- HPE OneView
- HPE Ezmeral Software platform
- HPE OpsRamp Software
Knowledge Base
Discussions
Forums
Discussions
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
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-18-2000 09:17 AM
07-18-2000 09:17 AM
using grep in script
cat myfile | grep "Jul 15"
and this works. When I try this in a script like:
cat myfile | grep "Jul 18"
it works, but when I try to use a variable I can't get the script to work:
set ""Jul 15""
echo $1
cat myfile | grep $1
even though the echo gives "Jul 15" . Also the script:
cat myfile | grep $1
will not work for "Jul 15" as the input argument. I cannot get a script to work with any command line argument that has more than a single string. Does someone know how to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2000 09:21 AM
07-18-2000 09:21 AM
Re: using grep in script
DATE=`date %'+b +d'`
grep $DATE
I am assuming that you are wanting something to look for dates. This is for the current date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2000 09:31 AM
07-18-2000 09:31 AM
Re: using grep in script
Rick is right. The catch is in the difference between single and double quotes. This is sometimes confusing when writing shell scripts.
Bye,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2000 09:39 AM
07-18-2000 09:39 AM
Re: using grep in script
Supplement:
When you like to pass a command line argument that contains whitespace as a single positional argument, enclose it in quotes.
Like:
myscript "This is a test"
$1 will contain the string "This is a test" (without the quotes).
If you want to use it as an argument to yet another command which should consider it as 1 positional argument, you should do
grep "$1"
Bye again,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2000 11:48 AM
07-18-2000 11:48 AM