Thursday, 11 May 2017

Use of egrep command

egrep : This command stands for extended grep.It is a combination of grep & fgrep along with some additional wild card characters.
Additional wild card characters like:

a)( | ) : It matches any one string in the given list.

Ex : $egrep "(oracle|java|unix)" output
It matches either oracle or java or unix strings.


b){m}: It matches exact occurrences of its preceding character or number.
Ex :$egrep "\<[0-9]{4}\>" num
It matches exact 4 digit number.

Ex: $egrep "\<[a-z]{4}\>" sample
It matches exact 4 digit string.

Ex: $egrep "\<ab{3}c\>" demo
It matches exact occurrence of its preceding number.

c){m,n}:It matches minimum 'm' occurrences and maximum 'n' occurrences of it's preceding character.
Ex: $egrep "\<ab{3,5}c\>" demo

Ex: $egrep "\<[0-9]{3,6}\>" num
It matches 3 or 4 or 5 or 6 digit numbers.

d){m,}: It matches minimum 'm' occurrences of its preceding character.
Ex :$egrep "\<ab{3,}c\>" demo

Ex :$egrep "\<[0-9]{3,}\>" num
It display minimum 3 digit number.

Use of fgrep command

fgrep : This command stands for faster grep.It is used to search multiple strings,but it doesn't allow to search regular expressions,it searches the strings more faster than the grep.

                                              Syntax : $frep "Strings" <filename>  

Ex:$fgrep "oracle
>unix
>java" output


                             
                    

Sunday, 16 April 2017

Use of Regular Expression

Regular Expression: String which contain wild card character known as regular expression or pattern.

Regular Expression or pattern divided into three types:
i)Character pattern: It is a default pattern
ii)Word pattern
iii)Line pattern

i)Character pattern:
a)Ex: $grep "ind*" demo

b)Ex: $grep "d[aeiou]" sample

c)Ex: $grep "d..l" sample
Note:.is a wild card character,it matches any single character.

ii)Word pattern:
\< \> : Word boundary
\< : Start of the word
\> : End of the word
a)Ex: $grep "\<india\>" demo

b)Ex: $grep "\<india" demo

c)Ex: $grep "india\>" demo

d)Ex : $grep "<\[0-9][0-9][0-9][0-9]\>" num

iii)Line pattern :
^ : Start of line
$ : End of line
a)Ex : $grep "^i" demo
It displays the lines starting with i.

b)Ex : $grep "^Re" departments
It displays the lines starting with Re.

c)Ex : $grep "^\<the\>" file
It displays the lines starting with the.

d)Ex : $grep "^[AIR]" departments
It display lines starting with A,I,R.

e)Ex : $grep "^[^AIR]" departments
It display lines not starting with A,I,R.

f)Ex : $grep "s$" departments
It display lines ending with s.

g)Ex : $grep "[0-9]$" alpha
It display lines ending with number.

h)Ex : $grep "^linux$" subject
It display lines containing linux.

i)Ex : grep ^...$ alpha
It display lines having exactly 3 character.

j)Ex : grep "^\." subject
It displays the line starting with . character.

k)Ex : grep "%\$" alpha
It displays line ending with % character.

l)Ex : grep "^$" alpha
It displays empty lines.


m)Ex : grep -c "^$" alpha
It counts number of empty lines.

n)Ex : grep -n "^$" alpha
It displays empty lines with line number.

o)Deleting empty lines from a file
Ex : $grep -v "^$" subject>output
Here output is an empty file.
Now output file contains all the non empty lines from subject file.

Sunday, 5 March 2017

Use of grep command

grep : grep command is used to search a string and regular expression from a given file.
                                      Syntax:$grep <string/pattern> filename
Ex :$grep india demo
It prints then line containing india.

Ex :$grep india demo demo1 demo2
It search india string from demp,demo1 & demo2 files and print lines having india.
Ex :$grep india *
It searches the india string from the current directory of all files.

Ex :$grep "indian politics" demo

Use of grep command with options:

a)Syntax :$grep -i "String" <filename>
Ex :$grep -i "India" demo
This command ignores case sensitive.

b)Syntax :$grep -c "String" <filename>
Ex :$grep -c "india" demo
This command counts number of lines having string india.

c)Syntax :$grep -n "String" <filename>
Ex :$grep -n "india" demo
This command counts lines with line numbers having string india.

d)Syntax :$grep -v "String" <filename>
Ex :$grep -v "india" demo
This command displays the lines do not having string india.
e)Syntax :$grep -o "String" <filename>
Ex :$grep -o "india" demo
This command prints only pattern containing india.


Saturday, 11 February 2017

Use of uniq command

uniq : This command is used to displays uniq lines in the given file but the file contents must be in sorted order.
                                    Syntax:$uniq <filename>
Ex:$uniq sample

a)uniq -u <filename> : It displays non duplicate lines.
                                  Syntax: $uniq -u <filename>
Ex :$uniq -u sample

b)uniq -d <filename> : It displays duplicate lines
                                   Syntax: $uniq -d <filename>
Ex :$uniq -d sample

c)uniq -c <filename> : It counts how many times the lines are repeated in the file.
                                   Syntax: $uniq -c <filename>
Ex :$uniq -c sample

Friday, 10 February 2017

Use disk status

df :This command is used to display disk space in bytes.

a)df :To display disk space in bytes.
                                  Syntax:$df
Ex :$df

b)df -h :To display disk space in kilo bytes.
                                Syntax:$df -h
Ex :$df -h

c)du :To display directory wise disk usage from of blocks and every block size 1024 bytes.
                              Syntax:$du
Ex :du

To use zip files

gzip gzip command is used for to zip the files.

a)gzip : gzip command is used for to zip the files.
                                          Syntax:$gzip <filename>
Ex :$gzip departments
zip file extension is .gz.

b)zcat : zcat command is used for to open zip files.
                                        Syntax:$zcat <filename.gz>
Ex :$zcat departments.gz

c)gunzip : gunzip command is used for to open zip files.
                                   Syntax:$gunzip <filename.gz>
Ex :$gunzip departments.gz