read a part of filename from the list in the script

how can i read a part of filename from the list in the script?

all file in directory...will start with "CDBACKUPFILE" then the name is stored in list.txt such as JOHN,MARRY,PETER. After this, is seq number.

CDBACKUPFILEJOHN00001
CDBACKUPFILEMARRY00004
CDBACKUPFILEPETER00003

I will use: ls -l CDBACKUPFILE*.archived to list out file.

can I write a script to read a file "list.txt" and the script can put JOHN, MARRY, PETER, etc into the statement?

Hi
You could first discard the CDBACKUPFILE string by using a substring command based on the length of this first parameter.
Then use a filter to remove any number from your string, or alternatively a substring command if your seq number has a fixed length.

I don't give you the code as I don't have the time to test it :slight_smile: I just hope this will indicate you how to do the job.

You can try something like this :

while read name
do
   ls -l CDBACKUPFILE${name}*.archived
done <list.txt

Jean-Pierre.

Hi, here's a suggestion. i dont hv unix on this comp so plz try it out n lemme know the results

ls -l|while read line
do
#the followng will first cut out the CDBACKUPFILE, then using awk, i'll specify
#0 as the field delimiter and print out the first field, which will be the name
cut -c 1-12|awk -F"0" '{print $1}'>file.txt
done