I have an input file named test.txt
like this:
Homo sapiens
Mus musculus
Rat rattus rattus
I want to use a for
loop here and loop through each line. Some thing like this:
for i in "`cat test.txt`"
do
fn=store_name
do something else > ${fn}.txt
done
Since each line has a space between names I used double quotes in cat test.txt
. I want to make a variable fn
which attaches _
between these names of the lines so my fn
becomes Homo_sapiens
and Mus_musculus
and if I have Rat rattus rates
it becomes Rat_rattus_rattus
How can I achieve this?
for
to read lines, it's just over complicating it when there are so many cleaner safer ways to do this. – slm Aug 01 '18 at 20:27