Originally Posted by ameylimaye
i have to grab a pattern using "grep" and save it in a file.
Originally Posted by colucix
Use a pipe to send the standard output of moshell to grep, e.g.
moshell | grep pattern
And to store the results to a file,
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
somecommand | grep pattern
would fail, whereas
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:
cat inputfile | grep pattern > output
grep pattern < inputfile > output
grep pattern inputfile > output