LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-02-2015, 03:51 AM   #1
LYC
Member
 
Registered: Jan 2014
Posts: 100

Rep: Reputation: Disabled
script queries


Hi,

Below is the output of the "date" command:
Thu Apr 2 16:07:59 SGT 2015

After assigning the output to a parameter as follows:
DATE=`date`

The output has changed when "echo $DATE":
Thu Apr 2 16:09:40 SGT 2015
^^

The "2" has moved forward.

I don't want the "2" to move forward, please advise how to go about it.

Thanks in advance.
 
Old 04-02-2015, 03:55 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
would be nice to use [code]here comes your example[/code] to keep formatting. Otherwise noone will see your problem
Try:
Code:
echo "$DATE"
(instead of echo $DATE)
 
1 members found this post helpful.
Old 04-02-2015, 04:37 AM   #3
LYC
Member
 
Registered: Jan 2014
Posts: 100

Original Poster
Rep: Reputation: Disabled
Hi,

Thanks it is working.

Another query about date:

I use the following to replace the "0" with space in front of the date:
Code:
DATE=`date +"a %b %d" | sed 's/0/ /'`
The output produced "Thu Apr 2" instead of "Thu Apr 02". The result is what I wanted but it will also remove "20" to "2". That is "Thu Apr 20" becomes "Thu Apr 2", the result is not I wanted.

Is there a way to work around?
 
Old 04-02-2015, 04:40 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,832

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
Check the format modifier you are using - you asked for the leading zero.
 
Old 04-02-2015, 04:43 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
sure, you need to replace <space>-and-0: sed 's/ 0/ /' for example, but you can also try: date +%-d
(if you really want to say thanks just click on yes)
 
2 members found this post helpful.
  


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
Script queries LYC Linux - Newbie 1 09-19-2014 06:42 AM
Script to mail output of Mysql Queries adarshmca Linux - Newbie 2 03-15-2011 08:58 PM
Script to mail Mysql Queries adarshmca Linux - Newbie 1 02-15-2011 08:48 AM
PHP Script to retrieve queries from log file saravanan1979 Programming 1 03-17-2002 09:13 AM


All times are GMT -5. The time now is 04:20 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