jeo_fb
November 17, 2018, 2:34pm
1
Hi all,
I have many files included time information, some of them included time range by 30 minutes;
2007-12-27T110000.txt
2007-12-27T120000.txt
2007-12-27T130000.txt
2007-12-27T150000.txt
2007-12-27T153000.txt
2007-12-28T000000.txt
2007-12-28T003000.txt
I only want to echo that if two files are in the range by 30 minutes like;
2007-12-27T150000.txt
2007-12-27T153000.txt
2007-12-28T000000.txt
2007-12-28T003000.txt
Please help!
Thanks
RudiC
November 17, 2018, 6:00pm
2
How about
$ for FN in 2007*.txt; do T1=${FN#*T}; T1=${T1%.*}; if (( T1 - 3000 < T2)); then echo $FN, $OFN; fi; OFN=$FN; T2=$T1; done
2007-12-28T000000.txt, 2007-12-27T153000.txt
2007-12-28T003000.txt, 2007-12-28T000000.txt
as a starting point?
jeo_fb
November 19, 2018, 5:28am
3
rudic:
How about
$ for FN in 2007*.txt; do T1=${FN#*T}; T1=${T1%.*}; if (( T1 - 3000 < T2)); then echo $FN, $OFN; fi; OFN=$FN; T2=$T1; done
2007-12-28T000000.txt, 2007-12-27T153000.txt
2007-12-28T003000.txt, 2007-12-28T000000.txt
as a starting point?
I tried but nothing appeared.
I am very new at unix. Please help
RudiC
November 19, 2018, 6:00am
4
No error msgs, obviously. Pls post the directory listing. Run the proposal witrh the -x
(xtrace) option set, and post the output. What's your shell version?
jeo_fb
November 19, 2018, 1:06pm
5
Thank you
It works but it is not in the true order.
2007-12-28T000000.txt, 2007-12-27T153000.txt
2007-12-28T003000.txt, 2007-12-28T000000.txt
I want to files only like below;
2007-12-28T000000.txt, 2007-12-27T150000.txt
2007-12-28T003000.txt, 2007-12-27T153000.txt
RudiC
November 19, 2018, 4:47pm
6
So - what did you change from post#3 to #5 ?
Date / time arithmetic is among the ugliest problems in IT. Try this slightly adapted version that IS NOT PREPARED to cross midnight:
for FN in 2007*.txt; do T1=${FN#*T}; T1=${T1%.*}; if (( T1 - 3000 <= T2)); then echo $OFN$'\n'$FN; fi; OFN=$FN; T2=$T1; done
2007-12-27T150000.txt
2007-12-27T153000.txt
2007-12-27T153000.txt
2007-12-28T000000.txt
2007-12-28T000000.txt
2007-12-28T003000.txt
EDIT: seems to cross midnight, but is far from robust:
for FN in 2007*.txt; do T1=${FN#*T}; T1=${T1%.*}; if (( (240000 + 10#$T1 - 10#$T2) % 240000 <= 3000)); then echo $OFN$'\n'$FN; fi; OFN=$FN; T2=$T1; done
2007-12-27T150000.txt
2007-12-27T153000.txt
2007-12-28T000000.txt
2007-12-28T003000.txt