- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: scanning the contents of a variable
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
тАО08-11-2005 06:38 AM
тАО08-11-2005 06:38 AM
What I am trying to do is this: I have a variable which contains a long string like the following.
VAR="Some text. Some more text. Even more text."
What I want to do is scan or grep the contents for a certain set of characters. Just like I was grepping a file for a certain string.
What, if anything, am I missing here?
Any help would be greatly appreciated.
Thanks,
-Bryan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2005 06:46 AM
тАО08-11-2005 06:46 AM
Re: scanning the contents of a variable
echo the contents the the $VAR then pipe that through grep
- Tags:
- echo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2005 06:46 AM
тАО08-11-2005 06:46 AM
Solutionif you are only concerned that if the string contains the substring you are looking for in a binary manner, i.e. "yes it contains" or "no it doesn't contain"
echo $string | grep -q $substring
r=${?}
if [ $r -eq 0 ]
then
echo "Substring was in the string"
else
echo "String sis not contain any of substring"
fi
hope this helps
UNIX because I majored in cryptology...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2005 06:47 AM
тАО08-11-2005 06:47 AM
Re: scanning the contents of a variable
echo $VAR |grep
echo $VAR |awk ' /
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2005 06:48 AM
тАО08-11-2005 06:48 AM
Re: scanning the contents of a variable
Not sure what you're looking for in your results - does this do anything for you:
VAR="Some text. Some more text. Even more text."
echo $VAR |grep text
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2005 06:53 AM
тАО08-11-2005 06:53 AM
Re: scanning the contents of a variable
My $.02...
echo "${var}" | grep "$text" > /dev/null 2>&1
[[ $? -eq 0 ]] && echo "Text found" || echo "Text NOT FOUND"
HTH;
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2005 06:56 AM
тАО08-11-2005 06:56 AM
Re: scanning the contents of a variable
I did the
echo $VAR | grep 'text'
option and it just returned the entire contents of the variable. As if it only did the echo portion of the command. I will try it again, maybe I fat fingered something.
-Bryan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2005 06:59 AM
тАО08-11-2005 06:59 AM
Re: scanning the contents of a variable
what did you expect to get instead ?
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2005 07:06 AM
тАО08-11-2005 07:06 AM
Re: scanning the contents of a variable
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2005 07:07 AM
тАО08-11-2005 07:07 AM
Re: scanning the contents of a variable
I guess I was expecting it to output just the text it was grepping for!
D'oh! Thanks to everybody who responded.
Special thanks to Mel and Doug for providing me with a means for getting the result I was looking for. If I would have really thought about what I was doing I would not have had to post in the first place.
Thanks!
-Bryan