Your Only Destination To Empower Your Computer Programing Knowledge. Sky is not so high, You can Touch it if You Try

Script for making use of multiple options of grep command

vi grep and press enter
.

echo "Enter the database"
read a
echo
echo database is:-
cat $a
echo
echo "Search given patterns from database"
echo enter the salary
read s1
grep $s1 $a
echo
echo search those pattern in which age 22:-
grep -n 22 $a
echo
echo Do not display those pattern having age 22:-
grep -v 22 $a
echo
echo Searching multiple pattern of salary 23000 and name start with m:-
grep -e m -e 23000 $a
echo
echo Showing the use of character class:-
grep "[Mn]eenu" $a
echo
echo show the use of ^ to specify the pattern location
grep "^n" $a


~
~
Output:-
sh grep and press enter
Enter the database
Database

database is:-
|Name |Age |salary |contact no.
|Meenu |23 |40000 |7206297384
|jyoti |20 |35000 |9813456782
|mamta |21 |32000 |9017720166
|kavita |22 |30000 |9014445623
|neha |23 |34500 |8014465777
|sanchi |24 |23000 |9014356278
|nishtha |25 |24567 |7289786254
|mohina |19 |45000 |9824568753
|mohit |22 |43000 |7013442455
|pooja |21 |34590 |9013324658
|monika |34 |23000 |7823445678
|neenu |33 |34000 |8076543210

Search given patterns from database
enter the salary
3000
|sanchi |24 |23000 |9014356278
|monika |34 |23000 |7823445678

search those pattern in which age 22:-
5: |kavita |22 |30000 |9014445623
10:|mohit |22 |43000 |7013442455

Do not display those pattern having age 22:-
|Name |Age |salary |contact no.
|Meenu |23 |40000 |7206297384
|jyoti |20 |35000 |9813456782
|mamta |21 |32000 |9017720166
|neha |23 |34500 |8014465777
|sanchi |24 |23000 |9014356278
|nishtha |25 |24567 |7289786254
|mohina |19 |45000 |9824568753
|pooja |21 |34590 |9013324658
|monika |34 |23000 |7823445678
|neenu |33 |34000 |8076543210

Searching multiple pattern of salary 23000 and name start with m:-
|Name |Age |salary |contact no.
|mamta |21 |32000 |9017720166
|sanchi |24 |23000 |9014356278
|mohina |19 |45000 |9824568753
|mohit |22 |43000 |7013442455
|monika |34 |23000 |7823445678

Showing the use of character class:-
|Meenu |23 |40000 |7206297384
|neenu |33 |34000 |8076543210

show the use of ^ to specify the pattern location
|neha |23 |34500 |8014465777
|nishtha |25 |24567 |7289786254
|neenu |33 |34000 |8076543210

No comments:

Post a Comment