This article introduces how to use shell to process daily data instances in linux. You can refer to this article for operations based on the directory date, but it is not applicable to cross-month operations.
Date loops are useful in processing data stored by date. Especially test and record, delete, and reprocess data. However, in the case of cross-month or other situations, it is impossible to simply use a numerical loop.
This shell can be used to process data from multiple days.
| The Code is as follows: |
Copy code |
#! /Usr/bin/env bash # Author: Andy Zhou # Date: 2013.8.6 Source dateutil. sh Begin in = 20130701 End = 20130904 For (d = $ begin; d <= $ end; d = 'getnextday $ D'); do Echo "date:" $ d #. Myshell. sh $ d |
Date tool dateutil. sh:
| The Code is as follows: |
Copy code |
#/Usr/bin/env bash # Author: Andy Zhou # Date: 2013.8.2 Getnextday () { # Date-d "2013-09-10 + 1 day" + % Y-% m-% d Date-d "$1 + 1 day" + % Y % m % d } Getyearmonth () { Date + % Y % m -- date = $1 # 1_date } Getday () { Date + % d -- date = $1 # 1_date } Long_date () { Date + % Y-% m-% d -- date = $1 # 1_date } Short_date () { Date + % Y % m % d -- date = $1 # longdate } Long_yesterday () { Date -- date = '1 day ago '+ % Y-% m-% d } Yesterday () { Date -- date = '1 day ago '+ % Y % m % d } Long_today () { Date + % Y-% m-% d } Today () { Date + % Y % m % d } Now () { Date '+ % Y-% m-% d % H: % M: % s' } Last_month () { Date -- date = '1 month ago ''+ % Y % m' } Year () { Date + % Y } Month () { Date + % m } Sec2date () { Date-d "1970-01-01 UTC $1 seconds" "+ % Y % m % d" } Sec2datetime () { Date-d "1970-01-01 UTC $1 seconds" "+ % Y % m % d % H: % M: % S" } |