1833703 Members
3158 Online
110062 Solutions
New Discussion

ls -lR Script problem

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

ls -lR Script problem

HI,

I have a file containing lists of filesystems:
#cat file1
/fs12/my_circuit
/fs13/schematics
/fs17/layout_archives
/fs21/chip_design
(and the list continues ...)

I would like to do an ls -lR for each of these filesystems in file1 and save the ls -lR of each of these filesystems into another file, i.e 1.txt, 2.txt, 3.txt to represent the 1st, 2nd, 3rd etc... filesystems from file1.
e.g:
/fs12/my_circuit should be stored in 1.txt
/fs13/schematics should be stored in 2.txt
/fs17/layout_archives should be stored in 3.txt

I did the following:
#cat myscript.sh
#!/bin/sh
count=0
for i in `cat file1`
do
count=`expr $count + 1`
ls -lR $i >> "$count".txt
count=`expr count`
done

Unfortunately, the filenames take the form of:
0.txt, 0+1.txt, 0+1+1.txt, 0+1+1+1.txt for the 1st, 2nd, etc filesystems to stored in the.

It would be best, however, if I could have the names of each files to be exactly similar to that of the filesystems i.e.:
/fs12/my_circuit should be stored in fs12/my_circuit.txt

/fs13/schematics should be stored in fs13/schematics.txt

Could someone show me the correct way of doing this? i.e as in having the filenames 1.txt, 2.txt OR even best, as in fs13/schematics.txt, fs12/my_circuit.txt ??

Thanks.
6 REPLIES 6
Steve Steel
Honored Contributor

Re: ls -lR Script problem

Hi

Put

typeset -i count=0


let count=$count+1


In place of the 2 current lines
count=0
count=`expr $count + 1`


steve steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Stefan Farrelly
Honored Contributor

Re: ls -lR Script problem

Try this;

for i in $(cat file1)
do
ls -lR $i > ${i}.txt
done
Im from Palmerston North, New Zealand, but somehow ended up in London...
Justo Exposito
Esteemed Contributor
Solution

Re: ls -lR Script problem

Hi Chern,

Try this:
cat myscript.sh
#!/bin/sh
integer count=0
for i in `cat file1`
do
(( count = $count + 1 ))
ls -lR ${i} >> ${count}.txt
done

Or:
#!/bin/sh
for i in `cat file1`
do
fich=$(echo ${i} | sed 's/\//_/g')
ls -lR ${i} >> ${fich}.txt
done

Regards,

Justo.
Help is a Beatiful word
Deepak Extross
Honored Contributor

Re: ls -lR Script problem

Try using
ls -lR $i >> "$i".txt
instead of
ls -lR $i >> "$count".txt
Steve Steel
Honored Contributor

Re: ls -lR Script problem

Hi

Forgot

do not need
count='expr count'
if you follow my previous answer

Also

>> $(echo $i|sed -e 's:/:\\:g')"_"$count".txt"

will give name \fs12\my_circuit_1.txt so you do
not need to make subdirectories but can recognise what it is.

steve steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Leif Halvarsson_2
Honored Contributor

Re: ls -lR Script problem

Hi

while read file
do
ls -lR $file >`basename $file`.txt
done