Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ls * script

Status
Not open for further replies.

olmos

Technical User
Oct 25, 2000
135
US
I have a file that contains a list partial names of files. From that list I need to do an ls command to find the complete name of the files and output it to another file.

For example : my file name_list contains
tom_smith
joe_doe
...

The above list is the beginning of the file names that I am looking for.

so I need to do an ls of each name , like this
ls tom_smith*.txt
ls joe_doe*.txt

I have this so far but it is not working...

---------------------------
#!/bin/csh -f

foreach i (`cat ./name_list`)

ls $i\*.txt >> datafile_name
echo $i
end

thanks,
olmos



 
#!/bin/ksh
eval ls $(sed 's!$!*.txt!' name_list) > datafile_name

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV, the script above is working except it only
outputs the first ls for the first name in name_list.

how can I fix this ?

thanks,
olmos
 
Code:
#!/bin/ksh

while read NAME
do
    ls -l ${NAME}*.txt
done < name_list > datafile_name

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top