I have a file like this
/*
Created by Bla bla bla
Copyright by XYZ
December 20th, 2020
*/
"car" = "Carro";
"door" = "Porta";
I would like to read this file line by line and copy to another file.
So I have this bash script
file='file.txt'
output='output.txt'
touch $output
for oneLine in $(cat ${file})
do
echo "$oneLine" >> $output
done
when I open the output file this is what I see
/*
Created by Bla bla bla
Copyright by XYZ
December 20th, 2020
Project/
Files/
Images/
Sounds/
in other words, when the parsing arrives at the line containing the *\
it prints a list of directories that in fact are directories that exist at the same level of the input and the output files.
How do I solve that?
for
. Hence it expands i.e.*/
to all files in current directory. Tryecho */
, orfor f in */; do echo "# $f #"; done
Not sure how you manage to get the whole lines from start of script. (First 6 lines). Suspect it's not your entire script. https://mywiki.wooledge.org/BashFAQ/001 - Wrote more in an answer but it got closed before I had a chance to post :P – ibuprofen Aug 17 '21 at 03:53$(cat ${file})
triggers word splitting and filename generation, and*/
is a pattern that matches all directories in the current dir. See also: http://mywiki.wooledge.org/WordSplitting and Quoting within $(command substitution) in Bash (That/*
should also already expand to some filenames, like/bin
,/etc
) – ilkkachu Aug 17 '21 at 08:25cat -- "$file" > "$output"
. (Or if you're actually trying to do something other than just copy, with an appropriate sed or awk script.) – ilkkachu Aug 17 '21 at 08:26