Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Write a shells scripts which will receives a list of filenames,the first of whch would be wordfile

Posted By: Molly Brown     Category: Unix / Linux / Ubuntu     Views: 3475

A file called wordfile consists of several words. Write a shells scripts which will receives a list of filenames,the first of whch would be word file.the shell script should report all occurrences of each word in
wordfile in the rest of the files supplied as arguments.

Code for Write a shells scripts which will receives a list of filenames,the first of whch would be wordfile in Unix / Linux / Ubuntu


    i=1
    cnt=`wc -l wordfile | cut -c 6-7`
    echo $cnt
    cp wordfile filefor22
    while [ $i -le $cnt ]
    do
        str=`head -1 filefor22`
        cnt1=`grep -c $str $1`
        echo $str $cnt1
        ((c=$i+1))
        tail +$c wordfile > filefor22
        let i++        
    done

--------------------------------------------------------------------------------

output:
    $ cat wordfile
    apple
    mango
    banana
    $ cat wordfile1
    apple
    chickoo
    apple
    banana
    $ sh27  wordfile1
    3
    apple 2
    mango 0
    banana 1
  
Share: 



Molly Brown
Molly Brown author of Write a shells scripts which will receives a list of filenames,the first of whch would be wordfile is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!