Bash Problem, strange new line!

I've been working on a BASH problem. I have this little script which, on a weekday (set by crontab) will run. It will grab the price of a unit trust from the legal and general website, clean up the output and email me the price. I want to create a CSV file of all the prices (the TICKER is one of my own choosing - I've not been able to find the correct ticker which will automatically download the prices to quicken)

(Since I first posted this, I've tweaked the script a little, trying to solve the bug - to no avail - I've replaced the code with the version as of 4th Jan 2008 - the bug is still present - note, ^M is actually ctrl-V ctrl-M, not carat-M)

 # Get the fund prices for L&G tracker and email me daily

# Get the file cd ~ wget -q --output-document=fundprices.txt

# Find the data I want grep --after-context=10 "UK Index Trust (Acc) (R)" fundprices.txt | sed -e :a -e 's/<[^>]*>//g;/ ~/fundprices.txt

# Trim Excess tabs tr -d '\t' < fundprices.txt > fundpricesout.txt

# I only want the closing price grep -m 1 '[0-9]' ~/fundpricesout.txt > fundprices.txt

# Output the CSV record for easier import to Quicken echo -n "LGTRKFTSE," >>fundprice.csv cat fundprices.txt >> fundprice.csv #BUG - THERE IS A NEW LINE CREEPING IN SOMEWHERE - IT NEEDS REMOVING echo -n "," >> fundprice.csv echo $(date +%d/%m/%Y) >> fundprice.csv

# Strip off the ctrl M characters sed 's/^M//g' fundprice.csv > fundpricesout.txt cp fundpricesout.txt fundprice.csv

# Mail me the price for the day mail -s "Prices for `date +%Y-%m-%d`" < ~/fundprices.txt

# Tidy up a bit rm fundpricesout.txt rm fundprices.txt 

The script emails me correctly, but unfortunately, I can't get the CSV to work. The output file looks like this:

LGTRKFTSE,169.6 ,02/01/2008

Where it should look like this:


How can I get rid of that annoying new line character? (I want to keep newlines between the entries for different days)

I'm sure it's something subtle but easy - but it's escaping me.... Anyone know the trick?