我有两个文件。在一个文件中我有每行中的其他文件我有每行数字的随机日期,这意味着:
菲尔1:
2018/06/24 14:17:19
2018/06/15 17:24:50
2018/07/15 10:25:29
文件2:
5938
1234
4567
所以,我想读的两个文件,并添加(以秒为单位)数量的日期,每行一个时间。
我的代码:
#!/bin/sh
IFS=$'\n'
for i in `cat fechas_prueba.txt`
do
for j in `cat duraciones.txt`
do
echo "$i - $j"
newDate=$(date -d "$i $j seconds" "+%Y/%m/%d %H:%M:%S")
echo $newDate >> sum_dates.txt
done
done
我想那个文件1和与文件2的第一行的第一线,与第二行第二行...这意味着:
2018/06/24 15:56:17
2018/06/15 17:45:24
2018/07/15 11:41:36
不过,我得到以下几点:
2018/06/24 15:56:17
2018/06/24 14:37:53
2018/06/24 15:33:26
2018/06/15 19:03:48
2018/06/15 17:45:24
2018/06/15 18:40:57
2018/07/15 12:04:27
2018/07/15 10:46:03
2018/07/15 11:41:36
所以,我怎么能与一号线仅和一号线,2号线2号线与等
谢谢!
可以使用类似的东西,为您的日期是在date.txt,第二要添加到这些日期是second.txt和你想要的最终结果将在finaldate.txt。
#!/bin/ksh
# Opening finaldate.txt for writing on file descriptor 3
exec 3>./finaldate.txt
# Read simultaneously the OriginalDate from file descriptor 4 and
# SecondToAdd from file descriptor 5
while read -u 4 OriginalDate && read -u 5 SecondToAdd; do
FinalDateInSecond=$(($(date -d "$OriginalDate" +"%s")+$SecondToAdd))
FinalDate=$(date -d @"$FinalDateInSecond" +"%Y/%m/%d %H:%M:%S")
# Printing the result on file descriptor 3
print -u 3 $FinalDate
# Having date.txt being read on file descriptor 4 while second.txt being
# read on file descriptor 5
done 4<date.txt 5<second.txt
希望它可以帮助