Linked Questions

Popular Questions

Make sum with two files but once time per line

Asked by At

I have two files. In one file I have a random date per line and in the other file I have a number per line, this means:

File1:

2018/06/24 14:17:19
2018/06/15 17:24:50
2018/07/15 10:25:29

File2:

5938
1234
4567

So, I want to reading the two files and add the number (in seconds) to the dates, one time per line.

My code:

#!/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

I want that the first line of file1 sum with the first line of file2, the second line with the second line... This means:

2018/06/24 15:56:17
2018/06/15 17:45:24
2018/07/15 11:41:36

However, I get the following:

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

So, How I can to only sum line1 with line1, line2 with line2, etc.

Thanks!

Related Questions