Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 26th, 2005, 10:08 AM   #1
technett
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 technett is on a distinguished road
help writing script to read files names

Hi there,
I am trying to do somehting similar, but on a wider scale.
I am trying to write a script that would open the home directory, open the first (of 650) user's folder
open the ?mail directory, which every user has

Then I need the script to read each of the files and folder names with one preceding directory and a carriage return as the delimiter.
Then the output is to be put into a file called .mailboxlist


cd /home
cd user1
cd mail
grep ls (this is where I am most stuck – adding the ‘mail/’ before each name and a carriage return as the delimiter) > .mailboxlist (??)
cp .mailboxlist /home/user1/.mailboxlist


The file “.mailboxlist” should look like this:
mail/Sent
mail/Trash
mail/Drafts
mail/tech support
mail/test1


After that is completed, I need the script to go to the next folder (user2) and do it again.

Any help would be greatly appreciated.
Thanks,
Nett
technett is offline   Reply With Quote
Old Apr 26th, 2005, 1:32 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
#!/bin/sh

# read a file, line by line (this could be an ls generated file)...
while f=`line`
do
$f
done < file.dat

echo "You're turn for effort"
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."

Last edited by Infinite Recursion; Apr 26th, 2005 at 1:34 PM.
Infinite Recursion is offline   Reply With Quote
Old Apr 26th, 2005, 1:38 PM   #3
technett
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 technett is on a distinguished road
THank you for your help.
I have gotten my script to look like this:

#!/bin/bash
cd /home
for user in `ls`
do
cd "$user"/mail
for dir in `ls`
do
echo mail/"$dir" >> /home/"$user"/.mailboxlist
done
cd /home
done

However, after running this script, I found that it script doesn't allow for spaces in names.
For instance, if there was a file named "2005 report", the script sees it as "2005" and "report" as two separate files.
How can I modify it to allow spaces or change the spaces to underscores?

Thanks,
Nett
technett is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC