while read LINE; do
echo $LINE | sed 's/ /%/g'
done < file > file2
When you echo a variable that contains multiple spaces, but you don't enclose the variable in double quotes, the multiple spaces are reduced down to one space. Then you can replace each single space with a percent sign. The resulting lines are placed in file2.
I kept trying it with one space and an asterisk, like 's/ */%/g' and it stuck a percent sign before every character.. why does two spaces do the trick?
thanks for restating my post.... IF you will re-read the first line of my post, you will notice I did say that this portion only removes blank lines..
My second example is for removing blanks in a data file. Assuming that there is no blank lines at the end of the line. You can expand this to work with data files that have upto 9 fields...
Just trying to show that there are different examples that work depending on your file... even though some are more encompassing than others...