Shell Scripting

Sunday, February 1, 2015

Useful Unix commands

CD:
cd ~ : To go to home directory.

cd - : Switches from current path to previous path.

$head :   It displays the first n lines from the file.
  Syn: $head –n filename
  Ex: $head -10 userlist.txt

$comm: It displays common lines b/w 2 files.
  Syn:$comm file1 file2

xmllint: To read XML file in unix
xmllint --format AbInitioWebServicesConfig.xml

Zip files:
zcat: it is used for to open zip file in readable format.
   $zcat sample.gz

gzgrep: view the content of GZ file by using below command
gzgrep -i "merchRepNum:[0-9]" McsApplication.txt*

Grep:
1)grep -i Running filename  ---ignore casesenstive
       2----
       5----
     
2)grep –c Running filename –-- counts no of lines
               3

3)grep –n Running filename ---- prints along with line no’s.
              2:--------
              5:-------
           
4)grep -l Running *  -- list only files
       file1
       file2
       file3
     
5)grep -v "Server started" filename –-- It will print the lines which are not matches

fgrep: [faster grep]
It is used for to search multiple strings. But it doesn’t allow to search regular expressions.

Ex: fgrep "pavan
      >unix
      >linux " filename
It searches either pavan or unix or linux

egrep:[ Extended grep]
It is a combination of grep and fgrep
Ex: egrep "pavan
      >unix
      >linux " filename
egrep "^d" filename

No comments:

Post a Comment