I made a small bash script which gets the current air pressure from a website and writes it into a variable. After the air pressure I would like to add the current date and write everything into a text file. The target should be a kind of CSV file.
My problem. I always get a line break between the air pressure and the date. Attempts to remove the line break by sed or tr '\n' have failed.
2nd guess from me: wget is done "too late" and echo is already done.
So I tried it with && between all commands. Same result.
Operating system is Linux. Where is my thinking error?
I can't get any further right now. Thanks in advance.
Sven
PS.: These are my first attempts with sed. This can be written certainly nicer ;)
#!/bin/bash
luftdruck=$(wget 'https://www.fg-wetter.de/aktuelle-messwerte/' -O aktuell.html && cat aktuell.html | grep -A 0 hPa | sed -e 's/<[^>]*>//g' | sed -e '/^-/d' | sed -e '/title/d' | sed -e 's/ hPa//g')
datum=$(date)
echo -e "${luftdruck} ${datum}" >> ausgabe.txt
aktuell.html && cat aktuell.htmlwith a-.echo -eis a bug here; you want simplyecho, orprintf&&doesn't have anything to do with this;&&means "run the next command only if the first command succeeds". In this case, the&&is actually appropriate (it shouldn't try to use the file if it wasn't downloaded successfully), but for reasons that have nothing at all to do with the problem you're trying to solve.sed -e ... | sed -e ...intosed -e ... -e ...orsed -e '...; ...'. It is not only shorter, but also way faster (even though it does not really matter in this case).