Skip to main content
added 14 characters in body
Source Link
Joseph R.
  • 40.6k
  • 8
  • 115
  • 146

Here you go:

select date in dates=($(for i in backups/*.tar.bz2;do #Glob eliminates need to list all files
                 date=${i/Complete Backup /} #Remove "Complete Backup "
                 date=${date%%.*} #Remove ".tar.bz2"
                 date=${date/ /,} #Substitue , for space
                 echo $date #Echo the date for sed
               done|sed -e 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)$/\1:\2:\3/'|sort -rr|xargs echo))
select date in ${dates[@]};do
    echo "$date"
done

One more thing: if you're using this for a select loop, how are you going to tell the different dates apart when they're space-separated? I mean you use space to separate the date from the time as well so this might be a source of confusion.

Edit

  • Added sorting of the dates from newest to oldest since your comments indicate that you need them sorted that way.
  • Added code to separate date and time by a comma so that select can tell a date and time pair from a new entry altogether.
  • WrappedWrapped the whole in a select loop Stored the whole indates into an array which is then iterated over by a select loop to avoid having to re-parse the dates for each re-run of the loop.

Here you go:

select date in $(for i in backups/*.tar.bz2;do #Glob eliminates need to list all files
                 date=${i/Complete Backup /} #Remove "Complete Backup "
                 date=${date%%.*} #Remove ".tar.bz2"
                 date=${date/ /,} #Substitue , for space
                 echo $date #Echo the date for sed
               done|sed -e 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)$/\1:\2:\3/'|sort -r);do
    echo "$date"
done

One more thing: if you're using this for a select loop, how are you going to tell the different dates apart when they're space-separated? I mean you use space to separate the date from the time as well so this might be a source of confusion.

Edit

  • Added sorting of the dates from newest to oldest since your comments indicate that you need them sorted that way.
  • Added code to separate date and time by a comma so that select can tell a date and time pair from a new entry altogether.
  • Wrapped the whole in a select loop.

Here you go:

dates=($(for i in backups/*.tar.bz2;do #Glob eliminates need to list all files
             date=${i/Complete Backup /} #Remove "Complete Backup "
             date=${date%%.*} #Remove ".tar.bz2"
             date=${date/ /,} #Substitue , for space
             echo $date #Echo the date for sed
         done|sed -e 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)$/\1:\2:\3/'|sort -r|xargs echo))
select date in ${dates[@]};do
    echo "$date"
done

One more thing: if you're using this for a select loop, how are you going to tell the different dates apart when they're space-separated? I mean you use space to separate the date from the time as well so this might be a source of confusion.

Edit

  • Added sorting of the dates from newest to oldest since your comments indicate that you need them sorted that way.
  • Added code to separate date and time by a comma so that select can tell a date and time pair from a new entry altogether.
  • Wrapped the whole in a select loop Stored the dates into an array which is then iterated over by a select loop to avoid having to re-parse the dates for each re-run of the loop.
added 34 characters in body
Source Link
Joseph R.
  • 40.6k
  • 8
  • 115
  • 146

Here you go:

select date in $(for i in backups/*.tar.bz2;do
  #Glob eliminates need to list all files
                 date=${i/Complete Backup /} #Remove "Complete Backup "
                  date=${date%%.*} #Remove ".tar.bz2"
                  date=${date/ /,} #Substitue , for space
                  echo $date #Echo the date for sed
                done|sed -e 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)$/\1:\2:\3/'|sort -r);do
    echo "$date"
done

One more thing: if you're using this for a select loop, how are you going to tell the different dates apart when they're space-separated? I mean you use space to separate the date from the time as well so this might be a source of confusion.

Edit

  • Added sorting of the dates from newest to oldest since your comments indicate that you need them sorted that way.
  • Added code to separate date and time by a comma so that select can tell a date and time pair from a new entry altogether.
  • Wrapped the whole in a select loop.

Here you go:

select date in $(for i in backups/*.tar.bz2;do
                   date=${i/Complete Backup /} #Remove "Complete Backup "
                  date=${date%%.*} #Remove ".tar.bz2"
                  date=${date/ /,} #Substitue , for space
                  echo $date #Echo the date for sed
                done|sed -e 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)$/\1:\2:\3/'|sort);do
    echo "$date"
done

One more thing: if you're using this for a select loop, how are you going to tell the different dates apart when they're space-separated? I mean you use space to separate the date from the time as well so this might be a source of confusion.

Edit

  • Added sorting of the dates since your comments indicate that you need them sorted.
  • Added code to separate date and time by a comma so that select can tell a date and time pair from a new entry altogether.
  • Wrapped the whole in a select loop.

Here you go:

select date in $(for i in backups/*.tar.bz2;do #Glob eliminates need to list all files
                 date=${i/Complete Backup /} #Remove "Complete Backup "
                 date=${date%%.*} #Remove ".tar.bz2"
                 date=${date/ /,} #Substitue , for space
                 echo $date #Echo the date for sed
               done|sed -e 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)$/\1:\2:\3/'|sort -r);do
    echo "$date"
done

One more thing: if you're using this for a select loop, how are you going to tell the different dates apart when they're space-separated? I mean you use space to separate the date from the time as well so this might be a source of confusion.

Edit

  • Added sorting of the dates from newest to oldest since your comments indicate that you need them sorted that way.
  • Added code to separate date and time by a comma so that select can tell a date and time pair from a new entry altogether.
  • Wrapped the whole in a select loop.
edited body
Source Link
Joseph R.
  • 40.6k
  • 8
  • 115
  • 146

Here you go:

select date in $(for i in /backups/*.tar.bz2;do
                  date=${i/Complete Backup /} #Remove "Complete Backup "
                  date=${date%%.*} #Remove ".tar.bz2"
                  date=${date/ /,} #Substitue , for space
                  echo $date #Echo the date for sed
                done|sed -e 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)$/\1:\2:\3/'|xargs'|sort);do
    echo "$date"
done

One more thing: if you're using this for a select loop, how are you going to tell the different dates apart when they're space-separated? I mean you use space to separate the date from the time as well so this might be a source of confusion.

As a possible workaround, you can pass the -d switch to xargs and specify a different delimiter instead of the default (space). You can thus say (for instance): ...|xargs -d',' echoEdit

  • Added sorting of the dates since your comments indicate that you need them sorted.
  • Added code to separate date and time by a comma so that select can tell a date and time pair from a new entry altogether.
  • Wrapped the whole in a select loop.

Here you go:

for i in /backups/*.tar.bz2;do
    date=${i/Complete Backup /} #Remove "Complete Backup "
    date=${date%%.*} #Remove ".tar.bz2"
    echo $date #Echo the date for sed
done|sed -e 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)$/\1:\2:\3/'|xargs echo

One more thing: if you're using this for a select loop, how are you going to tell the different dates apart when they're space-separated? I mean you use space to separate the date from the time as well so this might be a source of confusion.

As a possible workaround, you can pass the -d switch to xargs and specify a different delimiter instead of the default (space). You can thus say (for instance): ...|xargs -d',' echo

Here you go:

select date in $(for i in backups/*.tar.bz2;do
                  date=${i/Complete Backup /} #Remove "Complete Backup "
                  date=${date%%.*} #Remove ".tar.bz2"
                  date=${date/ /,} #Substitue , for space
                  echo $date #Echo the date for sed
                done|sed -e 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)$/\1:\2:\3/'|sort);do
    echo "$date"
done

One more thing: if you're using this for a select loop, how are you going to tell the different dates apart when they're space-separated? I mean you use space to separate the date from the time as well so this might be a source of confusion.

Edit

  • Added sorting of the dates since your comments indicate that you need them sorted.
  • Added code to separate date and time by a comma so that select can tell a date and time pair from a new entry altogether.
  • Wrapped the whole in a select loop.
edited body
Source Link
Joseph R.
  • 40.6k
  • 8
  • 115
  • 146
Loading
added 189 characters in body
Source Link
Joseph R.
  • 40.6k
  • 8
  • 115
  • 146
Loading
Source Link
Joseph R.
  • 40.6k
  • 8
  • 115
  • 146
Loading