LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-14-2015, 03:08 PM   #1
hnasr2001
Member
 
Registered: Nov 2012
Posts: 98

Rep: Reputation: Disabled
using grep to store the result in a variable


If I run the following two lines, the rsult will be 3;

myteststring1="radmon radmon radmon"
echo $myteststring1 | grep -o radmon | wc -l

How to store the result in a variable?
Thanks
 
Old 12-14-2015, 03:17 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by hnasr2001 View Post
If I run the following two lines, the rsult will be 3;

myteststring1="radmon radmon radmon"
echo $myteststring1 | grep -o radmon | wc -l

How to store the result in a variable?
Thanks
Code:
VARIABLE=$(echo $myteststring1 | grep -o radmon | wc -l)
Seems less than elegant. ;(
But it's all you gave me to work with.

Last edited by Habitual; 12-14-2015 at 04:58 PM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] assign full name to variable then grep a file for the variable socalheel Programming 3 09-16-2013 11:04 AM
how to store result of wc -l command in variable? trynq Linux - Newbie 11 04-20-2011 07:49 AM
Grep result passed to variable cornish Programming 5 11-15-2007 05:05 PM
multiline grep result > multiple variable? mikshaw Linux - Software 5 12-25-2003 10:13 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration