help writing script to read files names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help writing script to read files names
# 1  
Old 04-26-2005
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
# 2  
Old 04-26-2005
Are you looking for a snapshot of each of directory's under mail for all user's ?
# 3  
Old 04-26-2005
Quote:
grep ls (this is where I am most stuck - adding the ‘mail/' before each name and a carriage return as the delimiter) > .mailboxlist (??)
Unix uses a newline as a line terminator, not a carriage return. This tend to happen automatically. You need to do stuff to suppress it, not get it.

ls | sed 's=^=mail/=' > .mailboxlist

will do what I think you want. If you need something else, tell us what os and shell you are using.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Writing a loop to changing the names of files in a directory

Hi, I would like to write a loop to change the names of files in a directory. The files are called data1.txt through data1000.txt. I'd like to change their names to a1.txt through a1000.txt. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

2. UNIX for Dummies Questions & Answers

Writing awk script to read csv files and split them

Hi Here is my script that calls my awk script #!/bin/bash set -x dir="/var/local/dsx/csv" testfile="$testfile" while getopts " f: " option do case $option in f ) testfile="$OPTARG";; esac; done ./scriptFile --testfile=$testfile >> $dir/$testfile.csv It calls my awk... (1 Reply)
Discussion started by: ladyAnne
1 Replies

3. Shell Programming and Scripting

Need help in writing script for finding files in the unix machine?

I would like to find whether a file exists in the UNIX machine. That i can check using if ;then echo "exists" echo " `cat $file` " else echo "invalid file" fi. and i can find out using : find / -name "filename" . But it i have wanted to search in all directories. How to get... (3 Replies)
Discussion started by: rparsa001
3 Replies

4. Shell Programming and Scripting

writing script in UNIX for copying files in two server

can anyone help me in writing script in UNIX for copying files in two server from the third server after checking the files in the third server and if there is anything new in the third server automatically it should be added to the rest of the two servers and if same file is existing in the two... (4 Replies)
Discussion started by: REKHA09
4 Replies

5. Shell Programming and Scripting

help with a 'while read' loop to change the names of files

Hi, I am new to scripting, so any help on this would be much appreciated. I am trying to rename a bunch of files, taking the names sequentially from a list read in another file... # ls oldnames file_1 file_2 file_3 # cat names red yellow green I want the files to take on the... (6 Replies)
Discussion started by: starsky
6 Replies

6. Shell Programming and Scripting

How to get files names passed to a script

I need to get files names passed to a script. Here number of files passed may vary like MyScript.ksh file1 file2 file3..... so on I am writting script somthing like this set -A Files while (i<=$#) do File=$i let i=i+1 done Is this correct way doing this. Is there any other way.... (5 Replies)
Discussion started by: unishiva
5 Replies

7. Shell Programming and Scripting

Problems writing bash script to unzip files

I'm getting the following errors when I try to write a script to unzip some zip files. When I use the free trial copy of the commerical winzip program, however, they work fine. When I use -l or -t on unzip it indicates no errors. When I use the -o switch interactively from the bash command line it... (1 Reply)
Discussion started by: siegfried
1 Replies

8. UNIX for Dummies Questions & Answers

new to writing script files

thanks guys i managed to answer (0 Replies)
Discussion started by: bebop1111116
0 Replies

9. Shell Programming and Scripting

Writing a shell script to untar files

I am new to shell scripting and would appreciate any help I can get. I need to write a Unix shell script that I will run whenever I have a tar file to uncompress(Korn shell). Please put in mind that I have different environements that I will run it on. Thanks in advance ;) (4 Replies)
Discussion started by: nkem22
4 Replies

10. Shell Programming and Scripting

Script for writing to files with sed

I have a problem with syntax methinks, when it comes to sed. This is my script for a user to type sed commands:- yes=y function writefunction { $tool $command $newfilename $filename } echo echo echo "1. Type the name of the tool you are using i.e sed." read tool echo... (3 Replies)
Discussion started by: Trufla
3 Replies
Login or Register to Ask a Question