0

I have these files, for example:

20029181109173105_MAN_TDR.PLU
20029181109185001_MAN_TDR.PLU
20029181109185301_MAN_TDR.PLU
20029181109185601_MAN_TDR.PLU
20029181109185901_MAN_TDR.PLU

I need to copy the files that have in their names the date format that is greater than the current date, for this case it is "181109180000" (11th November, 2018 18:00h GMT-5).

  • You could help people make a lot fewer guesses if you spelled out the timestamp format of those ~17 digits... – Jeff Schaller Nov 13 '18 at 15:51
  • If it's YYmmddHHMMSS, then I don't understand how 181109 means 11-Nov-2018...? – Jeff Schaller Nov 13 '18 at 15:54
  • "iso" order (YYMMDD) with two digits for the year... – xenoid Nov 13 '18 at 15:56
  • looks like a mis-speak: should be "9th Nov 2018"' – glenn jackman Nov 13 '18 at 15:58
1

With bash, you can do this:

# the set-up
touch 20029181109173105_MAN_TDR.PLU 20029181109185001_MAN_TDR.PLU 20029181109185301_MAN_TDR.PLU 20029181109185601_MAN_TDR.PLU 20029181109185901_MAN_TDR.PLU

current=181109180000    # this would be `current=$(date "+%y%m%d%H%M%S")`

# the pay-off
for f in *PLU; do 
    if [[ $f =~ ^.....([0-9]{12}) ]] && [[ ${BASH_REMATCH[1]} -gt "$current" ]]; then 
        echo "$f"
    fi
done
20029181109185001_MAN_TDR.PLU
20029181109185301_MAN_TDR.PLU
20029181109185601_MAN_TDR.PLU
20029181109185901_MAN_TDR.PLU

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.