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

Related posts:

  1. History file in Linux and its Path History file in Linux is the file in which the...
  2. Maximum file size in FAT32 & NTFS The maximum size that you can have for a file...
  3. Remote Desktop Connection File Transfer Yes, you can transfer files over a remote desktop connection...
  4. Telnet and file uploading Did you know ? you can’t upload a file through...
  5. Purpose of Thumbs.db file in Win XP Ever wonder what is the purpose of that ‘thumbs.db’ file...
  6. How to run a FTP script in Windows? Not only Windows has a built-in command line FTP utility...

Trackback

no comment untill now

Add your comment now