LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2011, 06:04 AM   #1
ameylimaye
LQ Newbie
 
Registered: Aug 2011
Posts: 25

Rep: Reputation: Disabled
using grep command.


How do i use grep command without specifying the file name?

I mean..before using the grep command I am using "moshell" command...and its results to an information on the server itself....from the new information that is being displayed..i have to grab a pattern using "grep" and save it in a file.
I have to do it for a number of times...depending on the number of sites i am using moshell for.!

Can anyone help me in this case please.!
 
Old 09-01-2011, 06:08 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Use a pipe to send the standard output of moshell to grep, e.g.
Code:
moshell | grep pattern
 
Old 09-01-2011, 08:06 AM   #3
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Quote:
Originally Posted by ameylimaye View Post
i have to grab a pattern using "grep" and save it in a file.
Quote:
Originally Posted by colucix View Post
Use a pipe to send the standard output of moshell to grep, e.g.
Code:
moshell | grep pattern
And to store the results to a file,

Code:
moshell | grep pattern > output
which creates a file called "output" with the output of grep in it.

Note: on some systems (I think one Ubuntu that I used, at least) I've bumped into a situation where the pipe wouldn't work if I used a space after it; for example
Code:
somecommand | grep pattern
would fail, whereas
Code:
somecommand |grep pattern
would work. Not sure if it is/was a bug; I didn't have time to investigate. In any case, you don't need to leave spaces around the pipe character, if you don't want to (although that does make it more readable). The same applies to the >-character.

If you obtained the data from a file, rather than from standard output like above, you could use any of these (and probably some other) means:
Code:
cat inputfile | grep pattern > output
grep pattern < inputfile > output
grep pattern inputfile > output

Last edited by b0uncer; 09-01-2011 at 08:08 AM.
 
Old 09-02-2011, 01:14 AM   #4
ameylimaye
LQ Newbie
 
Registered: Aug 2011
Posts: 25

Original Poster
Rep: Reputation: Disabled
hey thanx a lot guys.!
I will try dese solutions and get back to you.!
 
Old 09-02-2011, 01:41 AM   #5
ameylimaye
LQ Newbie
 
Registered: Aug 2011
Posts: 25

Original Poster
Rep: Reputation: Disabled
IT worked.!
THANK YOU GUYS!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
command grep podariu Programming 3 02-11-2010 08:15 AM
Need help on grep command wjs1990 Linux - Newbie 2 12-14-2009 10:59 PM
How to pass the result of a command to another command (like grep) desb01 Programming 4 06-25-2009 01:09 PM
Help me in Grep Command + cd command in single line JeiPrakash Linux - Newbie 3 05-27-2008 05:16 AM
Help Use Grep Command, Thanks! zzytech Linux - Newbie 2 04-06-2006 12:37 AM


All times are GMT -5. The time now is 01:52 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration