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

Script to show the multiple option of awk command

echo enter the database
read a
echo
echo Contents of file are:-
cat $a
echo
echo show 1,2,3 column of given pattern :-
awk -F"|" '/[Mn]eenu/ { print $1, $2, $3 }' $a
echo
echo show data within range 3-6
awk -F"|" 'NR == 3, NR == 6 { print }' $a
echo
echo show record of jyoti in formatted way
awk -F"|" '/jyoti/ {
printf "%-7s %5d %-10d %12d\n",$1,$2,$3,$4 }' $a
echo
echo save record of jyoti in a file name result
awk -F"|" '/jyoti/ {
printf "%-7s %12d",$1,$4 }' $a > "result"
echo result file is:-
cat result

~
~
~
~
~
~
"awk" 17L, 506C


Output:-

enter the database
database

Contents of file are:-
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

Show 1,2,3 column of given pattern :-
Meenu 23 40000
neenu 33 34000

show data within range 3-6
jyoti |20 |35000 |9813456782
mamta |21 |32000 |9017720166
kavita |22 |30000 |9014445623
neha |23 |34500 |8014465777

show record of jyoti in formatted way
jyoti 20 35000 9813456782

save record of jyoti in a file name result
result file is:-
jyoti 9813456782

No comments:

Post a Comment