1

I need to make a script that returns 2 commands to a file.

But i would like them to be on the same line in the file.

The first command i want to use is speedtest-cli --csv and the second command is date '+%H:%M'

I searched on the internet and i found this:

{ date '+%H:%M' ; speedtest-cli --csv;} >> output.csv;

But when i use this the output file contains this:

21:18
11458,MyTheValentinus,Roubaix,2017-12-15T20:18:43.049067Z,34.53116198582131,32.416,20496907.000490207,3872939.885024341

while it needs to be on the same line.

How would i do this?

2 Answers 2

1

I assume you want to produce a valid .csv with comma separated values instead of having the time along with the first cell value of speedtest-cli --csv together in the first cell, then these commands should help (both doing the same thing):

printf "%s,%s" $(date +%R) "$(speedtest-cli --csv)" >>output.csv
echo $(date +%R),"$(speedtest-cli --csv)" >>output.csv

date +%R by the way is the same as date +%H:%M, whose format specifier doesn't need to be quoted.

1

Write like this:

{ printf "$(date '+%H:%M') "; speedtest-cli --csv; } >> output.csv

Or like this:

echo "$(date '+%H:%M') $(speedtest-cli --csv)" >> output.csv

Your approach didn't work because the date command produces output with a newline automatically appended.

When wrapped in a $(...), the last newline is not printed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .