I have a list of files (/c/Users/Roy/DataReceived
) over which I want to grep some information and store it as txt files(/c/Users/Roy/Documents/Result
).
For example purposes: Imagine I have a 20 files with different information about cities, and I want to grep information for the cities that are listed in a txt file. All this information will then be stored in another txt file that would have the name of the given city (NewYork.txt
, Rome.txt
, etc).
The following code is working:
#!/bin/bash
declare INPUT_DIRECTORY=/c/Users/Roy/DataReceived
declare OUTPUT_DIRECTORY=/c/Users/Roy/Documents/Result
while read -r city; do
echo $city
zgrep -Hwi "$city" "${INPUT_DIRECTORY}/"*.vcf.gz > "${OUTPUT_DIRECTORY}/${city}.txt"
done < list_of_cities.txt
However, the .txt files generated have an unrecognized format.
ls: cannot access 'NewYork'$'\n''.txt': No such file or directory
'NewYork'$'\n''.txt'
EDIT: I know what it is. This line of code > "${OUTPUT_DIRECTORY}/${city}.txt"
is not working properly, as it's storing the files as .txt/c/Users/Roy/Documents/Result/NewYork
. Not sure how to solve it