I have a text file (capital_names.txt
) containing lines like these:
Warsaw_
London_
Oslo_
...
In another file (capital_info.txt
) I have the following lines:
London_1_
London_2
cityLondon_3
capitalWarsaw_1
Warsaw_2
...
I wanted to write a shell script that greps capital names only if they are in the following format "Name_".
Desired outputs are multiple files like these:
$ cat Warsaw_output.txt
Warsaw_2
$ cat London_output.txt
London_1
London_2
Here is the key part of the script:
$outp=$"output"
while read line; do
grep ^$line capital_info.txt > $line$outp
done < capital_names.txt
However, the output files are empty (0 bytes) and have the following names:
'Warsaw_$'\r''output'
'London_'$'\r''output'
When I run individual commands (grep -f ^"London_" capital_info.txt
) everything works but I cannot do it for 50000 entries in capital_names.txt manually. How can I solve this issue?