Sponsored Content
Top Forums Shell Programming and Scripting Date increment in the format "YYYYMMDD" Post 302082416 by bin-doph on Wednesday 2nd of August 2006 05:27:50 AM
Old 08-02-2006
Hi,

Id go with a perl-onliner like this

Code:
perl -ne '$foo=time + 86400;@bar=localtime($foo);printf("%d%02d%02d",$bar[5]+1900,$bar[4]+1,$bar[3])'

note the 86400 which is the amount of seconds for a day. The advantage of this is, you dont have to care if your month has 30 or 31 days.

alternativly you could use something like this

Code:
expr `date +%Y%m%d` + 1

But that will give you a wrong date at the last day of the month.

hth
-fe
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. UNIX for Dummies Questions & Answers

converting date format: "May 31 2008" to "2008-05-31"

I have the following script to find out the last day of the last month .... and the output of this script is in the following format ... Script goes like this .... #!/bin/ksh cur_month=`date +%m` cur_year=`date +%Y` prev_month=$(($cur_month-1)) # Check to see if this is January if ... (8 Replies)
Discussion started by: santosham
8 Replies

3. UNIX for Advanced & Expert Users

add seconds to: date"|"time"|"HHMMSS

Hey all, I have a shell that invokes a AWK. In this AWK i want invoke a function that receives 3 parameters: date: 20080831 time: 235901 duration: 00023 that function receive this 3 parameters and sum to this value two more seconds: 2008083123590100025 Remember that in case that... (3 Replies)
Discussion started by: anaconga
3 Replies

4. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

5. Shell Programming and Scripting

Can someone help me to convert the date format after get it from the "LAST REBOOT" command.

Can someone help me to convert the date format after get it from the "LAST REBOOT" command. these is the standard output. bash-3.00# last reboot reboot system boot Fri Aug 6 15:07 reboot system down Fri Aug 6 15:04 reboot system boot ... (3 Replies)
Discussion started by: pichitw
3 Replies

6. Shell Programming and Scripting

Format output from the file to extract "date" section

Hello Team , I have to extract date section from the below file output. The output of the file is as shown below. I have to extract the "" this section from the above output of the file. can anyone please let me know how can we acheive this? (4 Replies)
Discussion started by: coolguyamy
4 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

How to increment date using "for loop" in format MMDDYY inside the shell script?

Need to increment the date from "currentdate + 90days" inside the for loop (i=1 to i=50) (5 Replies)
Discussion started by: aroragaurav.84
5 Replies

9. Shell Programming and Scripting

awk "date" and "system" command

Hello experts! I need your help please I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.: 2016-11-25 03:14:50and pass them to "date" command, but also append the 9th column in a file as well. So I want to execute date -d '2016-11-25 03:14:50' ... (2 Replies)
Discussion started by: phaethon
2 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
Devel::BeginLift(3pm)					User Contributed Perl Documentation				     Devel::BeginLift(3pm)

NAME
Devel::BeginLift - make selected sub calls evaluate at compile time SYNOPSIS
use Devel::BeginLift qw(foo baz); use vars qw($i); BEGIN { $i = 0 } sub foo { "foo: $_[0] "; } sub bar { "bar: $_[0] "; } for (1 .. 3) { print foo($i++); print bar($i++); } no Devel::BeginLift; print foo($i++); outputs - foo: 0 bar: 1 foo: 0 bar: 2 foo: 0 bar: 3 foo: 4 DESCRIPTION
Devel::BeginLift 'lifts' arbitrary sub calls to running at compile time - sort of a souped up version of "use constant". It does this via some slightly insane perlguts magic. import use Devel::BeginLift qw(list of subs); Calls Devel::BeginLift->setup_for(__PACKAGE__ => @list_of_subs); unimport no Devel::BeginLift; Calls Devel::BeginLift->teardown_for(__PACKAGE__); setup_for Devel::BeginLift->setup_for($package => @subnames); Installs begin lifting magic (unless already installed) and registers "${package}::$name" for each member of @subnames to be executed when parsed and replaced with its output rather than left for runtime. teardown_for Devel::BeginLift->teardown_for($package); Deregisters all subs currently registered for $package and uninstalls begin lifting magic is number of teardown_for calls matches number of setup_for calls. setup_for_cv $id = Devel::BeginLift->setup_for_cv(&code); Same as "setup_for", but only registers begin lifting magic for one code reference. Returns an id to be used in "teardown_for_cv". teardown_for_cv Devel::BeginLift->teardown_for_cv($id); Deregisters begin lifting magic referred to by $id. AUTHOR
Matt S Trout - <mst@shadowcatsystems.co.uk> Company: http://www.shadowcatsystems.co.uk/ Blog: http://chainsawblues.vox.com/ LICENSE
This library is free software under the same terms as perl itself perl v5.14.2 2012-04-22 Devel::BeginLift(3pm)
All times are GMT -4. The time now is 02:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy