LinuxQuestions.org
Review your favorite Linux distribution.
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 04-02-2015, 02:51 AM   #1
LYC
Member
 
Registered: Jan 2014
Posts: 109

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, 02:55 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
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, 03:37 AM   #3
LYC
Member
 
Registered: Jan 2014
Posts: 109

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, 03:40 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Check the format modifier you are using - you asked for the leading zero.
 
Old 04-02-2015, 03:43 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

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



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

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

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