CS699: Software Foundation Lab
Lab 2: Bash Scripting and Git Usage
Part 3 - Pattern Matching



Aim

  • Write a Bash or Shell (.sh) script which takes 2 command line arguments.
  • First argument is the name of the text file which contains words on each line.
  • Second argument is the path to a folder which contains subfolders and text files.
  • Your script should find each line which contains one word from the list of words provided using the first argument from all the text files present in the path provided using the second argument.
  • Each line which satisfies above criteria should be appended in the output file named output.txt in the format given below.
  • To execute the script:
    ./lab2_q3.sh list.txt files/
    
  • For example, suppose the word that you have to match is breathe. So your output should have a line like:
    path: files/dir1/addicted.txt line no.: 7 line: Could I breathe again?
    

    NOTE

    • Files should be traversed in directory order of the path names relative to the directory lab2_q3.
    • Hints: check for commands grep, sort, find.

Given

  • Skeleton zip file: lab2_q3.zip
    • Skeleton Bash file: lab2_q3.sh
    • Text file with list of words: list.txt
    • Folder with subfolders and text files: files
    • Output text file: output.txt

To check the content of folder q3:

$ ls -A q3/

Output of above command should look like:

q3
├── files
│   ├── dir1
│   │   └── addicted.txt
│   ├── dir2
│   │   └── seeyouagain.txt
│   ├── ilikeit.txt
│   └── temprature.txt
├── lab2_q3.sh
├── list.txt
└── output.txt

Part 3 will be checked via auto-grader, so make sure the file names and directory names are not changed and folder q3 consists of files/folders as mentioned above.



ALL THE BEST