LinuxQuestions.org
Review your favorite Linux distribution.
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, 09: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, 09:26 PM   #2
replica9000
Senior Member
 
Registered: Jul 2006
Location: USA
Distribution: Debian, FreeBSD, Android
Posts: 1,000
Blog Entries: 2

Rep: Reputation: 213Reputation: 213Reputation: 213
Code:
echo "`date` " >> date.txt && echo "something start" >> date.txt
 
1 members found this post helpful.
Old 05-16-2015, 09:43 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,028

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
Code:
[schneidz@hyper ~]$ date +Y"-hello world-"%j
2015-hello world-136
 
1 members found this post helpful.
Old 05-16-2015, 10: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 10:26 PM.
 
Old 05-17-2015, 07:23 AM   #5
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,078

Rep: Reputation: 195Reputation: 195
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, 11:35 AM   #6
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 934

Rep: Reputation: 104Reputation: 104
MYVAR=$(date) && echo "$MYVAR ciao"
 
Old 05-17-2015, 12:33 PM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,028

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 02:41 PM
bash: echo followed by command on the same line ??? RandyTech Linux - Newbie 11 02-01-2013 11:35 AM
bash, echo redirection not to the last line but first Xeratul Programming 2 09-03-2012 03:05 AM
need to echo / printf string containing date as parameter in cron v8625 Linux - Newbie 1 02-25-2011 07:31 PM
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Programming 2 10-08-2009 08:37 AM


All times are GMT -5. The time now is 06:42 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration