Computing.Net > Forums > Linux > help writing script to read files n

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

help writing script to read files n

Reply to Message Icon

Name: technett
Date: April 26, 2005 at 08:17:15 Pacific
OS: Linux TRed Hat 9
CPU/Ram: 2.3/512
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: 3Dave
Date: April 27, 2005 at 02:40:12 Pacific
Reply:

I would probably use perl myself (but thats just because I like it!), something along the lines of:
perl -e 'foreach $user(`ls /home`){`ls -1 /home/$user/mail > /home/$user/.mailboxlist`}'

I don't think that will prefix mail/ for each entry but it would be simple enough to put similar to the above into a script which opens a file and adds mail/ to each line before writing it....


0

Response Number 2
Name: Wolfbone
Date: April 27, 2005 at 03:51:39 Pacific
Reply:

for name in $(/bin/ls /home); do [[ -d /home/$name/mail ]] && for file in $(/bin/ls /home/$name/mail); do [[ -d /home/$name/mail/"$file" ]] && echo "mail/$file" >> /home/$name/.mailboxlist; done; done

( assuming it really should be "mail" rather than "Mail" )


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: help writing script to read files n

Script for read files in a director www.computing.net/answers/linux/script-for-read-files-in-a-director/28504.html

how to image file between two linux sys. www.computing.net/answers/linux/how-to-image-file-between-two-linux-sys/6503.html

Enough Permission TO Read Root? www.computing.net/answers/linux/enough-permission-to-read-root/14359.html