用自动生成的日期替换文本
Replace text with automatically generated dates
我有一个如下所示的文本文件
test tom
test fred
test harry
test jim
文本文件中有 12000 个名字。
我想用自动生成的日期替换单词 test,这样列表中的每个名字都会额外增加一个小时。所以我最终会得到以下内容:
2015-04-10 14:00 tom
2015-04-10 15:00 fred
2015-04-10 16:00 harry
2015-04-10 17:00 jim
一天结束后,它应该继续到第二天、下个月和下一年,直到结束。
bash 脚本如何做到这一点?
将其放入脚本中并将其命名为 whatever.sh
:
#/bin/bash
count=0
while read -r blah rest
do
echo "$(date -d "+$count hours" +"%F %H:00") $rest"
((count++))
done
使其可执行:
chmod +x whatever.sh
然后:
./whatever.sh < input.txt
使用 awk
awk 'BEGIN{x=systime()}{=strftime("%F %H:00",x);x+=3600}1' file
输出
2015-04-10 14:00 tom
2015-04-10 15:00 fred
2015-04-10 16:00 harry
2015-04-10 17:00 jim
我有一个如下所示的文本文件
test tom
test fred
test harry
test jim
文本文件中有 12000 个名字。
我想用自动生成的日期替换单词 test,这样列表中的每个名字都会额外增加一个小时。所以我最终会得到以下内容:
2015-04-10 14:00 tom
2015-04-10 15:00 fred
2015-04-10 16:00 harry
2015-04-10 17:00 jim
一天结束后,它应该继续到第二天、下个月和下一年,直到结束。
bash 脚本如何做到这一点?
将其放入脚本中并将其命名为 whatever.sh
:
#/bin/bash
count=0
while read -r blah rest
do
echo "$(date -d "+$count hours" +"%F %H:00") $rest"
((count++))
done
使其可执行:
chmod +x whatever.sh
然后:
./whatever.sh < input.txt
使用 awk
awk 'BEGIN{x=systime()}{=strftime("%F %H:00",x);x+=3600}1' file
输出
2015-04-10 14:00 tom
2015-04-10 15:00 fred
2015-04-10 16:00 harry
2015-04-10 17:00 jim