I am having a peculiar problem. First I run the code below to append 0 at the start of each line in some hundreds of files that I have in a directory. These files have each word in a newline.
for f in *.dat; do
echo "0" > tmpfile
cat $f >> tmpfile
mv tmpfile $f
done
Then I run this script to remove all the newlines, and convert them into space.
ls -1 *.dat | while read page
do
cat $page | awk '$1=$1' ORS=' ' $page > $page.txt
done
But I find that when the second code is run, it removes the 0's that I have put using the first code. Any idea how can this be corrected? But when I put any number greater than 0, the second code does not remove that number. I am using Linux with BASH.
Yes, "cat" was redundant. It was not needed anyway. But even after removing cat $page in the second script, the same problem of 0 getting removed still persists.