Using grep command in list of files
The grep command look inside a file and returns the line that contains the word searched. Here, it will return all lines containing genre that are found in a CHA file.
grep -i ’genre’ *.cha
Adding -C 3 > output.txt to the command will output three lines of context before and after, and will save the result in a file called output.txt. More complex request can be done. For instance, the following will output the number of time ‘SP11’ was found in each CHA file in the current folder.
for i in *.cha; do grep -i ’SP11’ $i | echo $i ‘wc -l‘; done