- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ls -lR Script problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 11:47 PM
08-26-2002 11:47 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 11:50 PM
08-26-2002 11:50 PM
Re: ls -lR Script problem
Put
typeset -i count=0
let count=$count+1
In place of the 2 current lines
count=0
count=`expr $count + 1`
steve steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 11:50 PM
08-26-2002 11:50 PM
Re: ls -lR Script problem
for i in $(cat file1)
do
ls -lR $i > ${i}.txt
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 11:53 PM
08-26-2002 11:53 PM
SolutionTry 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 11:54 PM
08-26-2002 11:54 PM
Re: ls -lR Script problem
ls -lR $i >> "$i".txt
instead of
ls -lR $i >> "$count".txt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2002 12:14 AM
08-27-2002 12:14 AM
Re: ls -lR Script problem
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2002 12:26 AM
08-27-2002 12:26 AM
Re: ls -lR Script problem
while read file
do
ls -lR $file >`basename $file`.txt
done