A problem for sed? Remove parts of a string

Hi,
My knowledge about sed is limited but I have a problem that I think can be solved with sed.

I have a variable in a shell script that stores a lot of path/filenames and the delimitter between them is a space (they all exist on the same line). One part of the filename is the file creation date.
Below an example of how a the variable store three instances of path/filenames:

/logdir/logfile_2008:08:12_Comp.Z /logdir/logfile_2008:08:13_Comp.Z
/logdir/logfile_2008:08:14_Comp.Z

I want to remove all path/filenames that doesn�t match an user specified interval of dates (handled earlier in the script). For example, maybe I have choosed the start date to 2008:08:14. That means that the instances with the dates 2008:08:12 and 2008:08:13 should be removed from the variable and the path/filename with the date 2008:08:14 should be kept in the variable.

How may this be solved with sed (or some other unix tool)?

Thanks,
Rick

So you have a variable containing space-separated tokens and you want to discard some of them? If you are processing them one at a time anyway, perhaps you want something like this:

for file in $variable; do
  # Skip rest of loop unless it matches 2008:08:14
  case $file in *2008:08:14*) : keep going ;;  *) continue;; esac
  : do whatever you want to do with $file
done

If you just want to collect the values into the variable, "do whatever you want to do" amounts to copying the matching values to a new variable, and assigning it back to the main variable after "done".

Hi,
I have noticed that it is all to slow to loop though the whole variable in a shell script. There may be hundreds or thousands path/filenames in the variable. That�s why I hope it is possible to solve with a tool like sed.

Thanks,
Rick

Use awk:

var='/logdir/logfile_2008:08:12_Comp.Z \
/logdir/logfile_2008:08:13_Comp.Z \
/logdir/logfile_2008:08:14_Comp.Z \
/logdir/logfile_2008:09:01_Comp.Z \
/logdir/logfile_2008:09:14_Comp.Z'

start=20080814
end=20080901
newvar=$(
printf "%s\n" $var |
 awk -F_ -v start=$start -v end=$end '
  {
   date = $2
   gsub( /:/,"",date )
  }
 date >= start && date <= end { printf "%s ", $0 }
'
)

It worked perfectly.
Thanks cfajohnson.