Show file name included time information

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

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 :frowning:

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?

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

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