-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
shell 实现N位自动补零和日期循环 - 京东放养的爬虫 - CSDN博客 https://blog.csdn.net/djd1234567/article/details/51570051 | ||
用awk的printf就可以补位 | ||
|
||
|
||
|
||
|
||
# 仅适用于数字 | ||
|
||
printf "%04d\n" 86 | ||
|
||
echo 86|awk '{printf("%04d\n",$0)}' | ||
|
||
|
||
|
||
|
||
下面是我实际应用中使用的一个脚本,目的是批量修改hdfs上的文件名,输入两个参数即可,就是开始时间和结束时间,然后用whil去循环。 | ||
|
||
|
||
#example------nohup sh hdfs_rename.sh 20160522 20160530 >>logrename 2>&1 & | ||
|
||
datebeg=$1 | ||
dateend=$2 | ||
|
||
beg_s=`date -d "$datebeg" +%Y%m%d` | ||
end_s=`date -d "$dateend" +%Y%m%d` | ||
|
||
|
||
while [ "$beg_s" -le "$end_s" ] | ||
do | ||
date=${beg_s} | ||
for i in `seq 99` | ||
do | ||
num1=`echo ${i}|awk '{printf("%06d\n",$0)}'` | ||
num2=`echo ${i}|awk '{printf("%02d\n",$0)}'` | ||
echo ${date} | ||
echo ${num1} | ||
echo ${num2} | ||
hadoop fs -mv /xtrader/${date}/${num1}_* /xtrader/${date}/xtrader_UserInfo_${date}_${num2}.gz | ||
done | ||
echo ${date} | ||
beg_s=`date -d"${beg_s}+1 day" +%Y%m%d` | ||
|
||
done | ||
--------------------- | ||
作者:djd已经存在 | ||
来源:CSDN | ||
原文:https://blog.csdn.net/djd1234567/article/details/51570051 | ||
版权声明:本文为博主原创文章,转载请附上博文链接! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
for i in `seq 1 100`; do echo $i ; done | ||
for i in {1..100}; do echo $i ; done |