LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash echo date+string in the same line (https://www.linuxquestions.org/questions/linux-newbie-8/bash-echo-date-string-in-the-same-line-4175542809/)

vrltwe 05-16-2015 08:12 PM

Bash echo date+string in the same line
 
I would like to print the date followed by a string (an indication of what's going on at that time) to a file. With this intention I've tried

Code:

date >> date.txt && echo "something start" >> date.txt
That gives me

Code:

Sun May 17 01:08:28 BRT 2015
something start

How to get both at the same line? Like this

Code:

Sun May 17 01:08:28 BRT 2015 something start

replica9000 05-16-2015 08:26 PM

Code:

echo "`date` " >> date.txt && echo "something start" >> date.txt

schneidz 05-16-2015 08:43 PM

Code:

[schneidz@hyper ~]$ date +Y"-hello world-"%j
2015-hello world-136


vrltwe 05-16-2015 09:15 PM

I'm opting for short @schneidz's way. Thanks!

arizonagroovejet 05-17-2015 06:23 AM

Quote:

Originally Posted by schneidz (Post 5363454)
Code:

[schneidz@hyper ~]$ date +Y"-hello world-"%j
2015-hello world-136


Code:

mike@continuity7:~$ date +Y"-hello world-"%j
Y-hello world-137
mike@continuity7:~$ date +%Y"-hello world-"%j
2015-hello world-137
mike@continuity7:~$

But that's a string mixed in with bits of the date and example OP gives of desired output
Code:

Sun May 17 01:08:28 BRT 2015 something start
which is date followed by a string.
Code:

mike@continuity7:~$ date "+%Y %j hello world"
2015 137 hello world
mike@continuity7:~$

is closer, but you'd have to specify all the date components


Code:

mike@continuity7:~$ echo "$(date) something start"
Sun 17 May 12:19:29 BST 2015 something start
mike@continuity7:~$


Pearlseattle 05-17-2015 10:35 AM

MYVAR=$(date) && echo "$MYVAR ciao"

schneidz 05-17-2015 11:33 AM

Quote:

Originally Posted by arizonagroovejet (Post 5363574)
Code:

mike@continuity7:~$ date +Y"-hello world-"%j
Y-hello world-137
mike@continuity7:~$ date +%Y"-hello world-"%j
2015-hello world-137
mike@continuity7:~$

But that's a string mixed in with bits of the date and example OP gives of desired output
Code:

Sun May 17 01:08:28 BRT 2015 something start
which is date followed by a string.
...

i left the rest as an excersize for the op to bang out on their own.


All times are GMT -5. The time now is 12:05 AM.