I have 20 files with different types of information for a list of cities.
For all the files, I want to grep the information of a given city, so, if for example I have three cities (NewYork, Barcelona, Rome), I would like to generate three files (NewYork.txt, Barcelona.txt, Rome.txt), with all the information in the 20 files for those cities.
I can do this easily with the script:
#!/bin/bash
list=("NewYork", "Barcelona", "Rome")
for i in "${list[@]}"
do
echo $i
zgrep -Hx $i *.vcf.gz > $i.txt
done
echo "Done"
However, there are two dificulties:
- First, the list of cities is huge, so I need the script to read a txt file with the list of cities for which I want the data, instead of creating the list manually inside the script.
- Secondly, the files with the information of the cities is in the folder
C:/Users/Roy/DataReceived
, and I want to store the output.txt
inC:/Users/Roy/Documents/Results
.
This is script I wrote:
#!/bin/bash
for FILE in C:/Users/Roy/DataReceived/*; do
while read i; do
zgrep -Hwi $i *.vcf.gz > $i.txt
done < list_of_cities.txt
done
This script would be stored in C:/Users/Roy/Documents/Results
, so there's where the files would be created.
However, I'm getting the error 'gzip: *.vcf.gz: No such file or directory'. It's not recognizing the file, so I guess there's something wrong with the path.