LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-16-2015, 08:12 PM   #1
vrltwe
LQ Newbie
 
Registered: Jul 2013
Posts: 11

Rep: Reputation: Disabled
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
 
Old 05-16-2015, 08:26 PM   #2
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
Code:
echo "`date` " >> date.txt && echo "something start" >> date.txt
 
1 members found this post helpful.
Old 05-16-2015, 08:43 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
[schneidz@hyper ~]$ date +Y"-hello world-"%j
2015-hello world-136
 
1 members found this post helpful.
Old 05-16-2015, 09:15 PM   #4
vrltwe
LQ Newbie
 
Registered: Jul 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
I'm opting for short @schneidz's way. Thanks!

Last edited by vrltwe; 05-16-2015 at 09:26 PM.
 
Old 05-17-2015, 06:23 AM   #5
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
Quote:
Originally Posted by schneidz View Post
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:~$
 
Old 05-17-2015, 10:35 AM   #6
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
MYVAR=$(date) && echo "$MYVAR ciao"
 
Old 05-17-2015, 11:33 AM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by arizonagroovejet View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash ECHO new line tkinsella Linux - Newbie 3 02-03-2014 01:41 PM
bash: echo followed by command on the same line ??? RandyTech Linux - Newbie 11 02-01-2013 10:35 AM
bash, echo redirection not to the last line but first Xeratul Programming 2 09-03-2012 02:05 AM
need to echo / printf string containing date as parameter in cron v8625 Linux - Newbie 1 02-25-2011 06:31 PM
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Programming 2 10-08-2009 07:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration