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

Monday, July 9, 2012

How to create script in Unix

First of all we need Unix environment to create the script.
  • 1. vi MyFirstScript.sh
  • 2. type echo "Hello World"
  • 3. exit and save :wq!
  • 4. change mode the file as a executable file => chmod 775 MyFirstScript.sh (I will tell about 775 later)
  • 5. now the script can be execute, type ./MyFirstScript.sh
  • 6. the output Hello World
tq...