How to get the dates from a list of file names?

Hi All,

I have a .txt file with the list of filenames as given below.

 
/dev_data/dev3/ctl/20120622_Employee.txt
/dev_data/dev3/ctl/20120623_Employee.txt
/dev_data/dev3/ctl/20120624_Employee.txt  

I want to read this file & write the dates alone from the filenames into a .done file.

Can anyone tell me how to get only the dates from this .txt file to the .done file delimited by comma ?

Thanks Much
Freddie

sed 's|.*/\([0-9]\{8\}\).*|\1|' inp.txt|paste -sd',' - > inp.done
in=/path/to/input/file
out=/path/to/output/file

awk -F/ '
{ sub(/_.*/,"",$NF); printf "%s,", $NF }
' "$in" > "$out"

not tested

perl -F"[\/_]" -lane 'push @a,$F[5];END{print join ",",@a}' input.txt
sed ':i;{s:\n:,:g;s:/.*/\|_Employee.txt::g;N;bi}' infile

Another way..

awk -F "[/_]" '{x= x $6 "," } END {sub(/,$/,"",x);print x}' file

Also (contains a trailing comma),

while read LINE
do
 a=${LINE%_*}
 echo -n ${a##*/},
done < file

This will work is ksh or bash shell:

$ cat test.txt
/dev_data/dev3/ctl/20120622_Employee.txt
/dev_data/dev3/ctl/20120623_Employee.txt
/dev_data/dev3/ctl/20120624_Employee.txt

$ for x in `cat test.txt`;do fn=${x##/*/};echo $fn>>files.done;done

$ cat files.done
20120622_Employee.txt
20120623_Employee.txt
20120624_Employee.txt