previousDay=`date +"%Y-%m-%d" -d "-1 day"`
finish_time1=$(grep -o -m1 "$previousDay [0-9][0-9]:[0-9][0-9]:[0-9][0-9]" sample.txt)
在這裏,我試圖找出給人一種date.Here最接近的前日期sample.txt的內容,以獲取從文件讀取特定日期之前的日期如何使用shell腳本
2013-11-07 15:53:49 HB Thread alive (1)
2013-11-07 15:53:49 heartBeatCallback starting fireHeartBeat
2013-11-07 15:53:50 refreshPollingTime END
2013-11-07 15:53:50 heartBeatCallback testing childpid
2014-01-24 15:53:50 heartBeatCallback end
2014-01-25 15:53:50 HB end callback call
2014-01-25 15:53:50 uploadTSLog TS_LOG_FILE is /public/tmp/testomatic/ts_logs/2013-11- 07_08-21-19_ONEOS90-VOIP_SIP_11N_FT-V5.1R5E12_NB83163_FT4_T10_112741.log
2014-01-27 15:53:50 uploadTSLog: no new logs to upload
2014-01-27 15:54:50 HB going to sleep */
所以這豈不工作? – hashbrown
我想要得到給定date.ex的前一天:給定日期爲2014-01-27,我希望下一前一天爲2014-01-25 – user3165241
不知道我是否正確回答問題... if給定日期是'2014-01-27',你想'2014-01-25',爲什麼不把''-1 day「'部分改爲''-2 day''? – hashbrown