Now that is a very basic thing! But it is not that simple when you are doing it for the 1st time and you don’t have much knowledge of scripting.
Suppose you want to write a script that counts that in how many lines the name of certain fruit came in a file

From command line you can do this by

grep –c   apples datafile.txt  

Now if you many things that you need to count then you will have to type the above commands for each of them but this can be also done through a small script but the question is that if I have many different data files than how I run the same script on all of them? The answer is in $1, $1 is the 1st parameter given from the command line to the script (which would be the name of data file in our case

#!/bin/bash

grep -c  apples $1
grep -c mango   $1
grep -c orange   $1

save the above script in a file ‘myscript’ set execute permissions and than for any datafile you can all the script by

./myscript  datafile

Trackback

no comment untill now

Add your comment now