Thursday, July 19, 2012

How to grep in Unix

Before this I have told about how to create executable script in Unix environment. And today I want to share together with how to grep in Unix. Basically grep is use to call *line that consist of grep word.
For example we can use this;
Assume that we have a file called "test.txt". And the content is like below;
abc def ghi jkl
aaa bbb ccc ddd
say we have abc

Now we can start grep like this;
grep abc test.txt

And the output is should be like this;
abc def ghi jkl
say we have abc

Or we can code like this;
cat test.txt|grep abc

The output should be same as below output;

abc def ghi jkl
say we have abc

And the last command which I want to share with u is how to grep a word with start character. The command is like this;
grep ^a test.txt

The output should be like this;

abc def ghi jkl
aaa bbb ccc ddd
say we have abc



*line : line of words, or sentence or line of character etc in a file or many files.
*cat : command for read file or create a file

All right, all the best to you.

p/s: if I have mistake don't be hesitate to let me know

No comments:

Post a Comment