Read directory and fill a file with this information


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Read directory and fill a file with this information
# 1  
Old 05-13-2009
Read directory and fill a file with this information

Hello All,

Got a question to make a script what reads a directory and put the file names from that directory in a file with some extra text.

ls /tempdir

output is:

file1.gfh
file2.txt
file4.zzz

these file names (always with an extention) must be placed in a line and written to a file

sample line could be:

this filename $filename with extention $extention is found and would be removed within 10 days

This output must be in one file.

Is this possible?


I know some small things how to do but cannot combine them and possible not all is correct :-)

ls /tempdir I know
how to put everything into a file


echo "this filename $filename with extention $extention is found and would be removed within 10 days" >> /test/output

but then it stops :-(

hope someone can help me further

regards Walt
# 2  
Old 05-13-2009
Code:
ls /tempdir |
while read filename
do
echo "this filename $filename is found and would be removed within 10 days"
done >> /test/output

Note: if the directory /test exists it is a really bad name for a file or a directory.
test is the name of a unix command. file names that match command names cause problems.
# 3  
Old 05-13-2009
Thank you Jim,

I will look and test it.

/test was just a sample thank you for the tip.

regards Walter
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How can I use my code to gather information from a file in a completely different directory?

I need my code to compare two different files that are in two completely different directories, How can I do this? So for example, my code will look at file1 which is in my home directory, and compare the files with those from file2 that is in /abc/adf/adr/afc/adf/file2... does that make sense? (1 Reply)
Discussion started by: castrojc
1 Replies

2. Shell Programming and Scripting

How to read userid and password information from txt file

Hi Experts, I am writing a shell script (for displaying disk space details) which is logging to 15 different servers using following command. ssh userid@servername It is prompting me for password for all 15 servers when I manually run it. However , soon I would like to schedule this script... (4 Replies)
Discussion started by: ajaypatil_am
4 Replies

3. Shell Programming and Scripting

Fill the directory

HI all When i do df -h,it displays the amount of free space. Tell me a command or a script to fill the total space to a certain percent (say 99%) Thanks in advance (8 Replies)
Discussion started by: 2002anand
8 Replies

4. Programming

How to read BGP session information with C

Friends, I want to read BGP session information with C ( in FreeBSD ). The program will almost work like a sniffer. My FreeBSD box (which is not a BGP speaker) will look at BGP session information (after catching and parsing it) and take a decision based on the information it sees. :wall: ... (1 Reply)
Discussion started by: asadfx
1 Replies

5. Shell Programming and Scripting

read file by file in a directory

Hi I have directory which has 5 files names test1, test2, test3, test4, test5 Now i want to read file by file and generate md5checksum. Command used is md5sum test1. How can i read file names one after the other and generate checksum and send the output to a file. Please reply (3 Replies)
Discussion started by: vasuarjula
3 Replies

6. Shell Programming and Scripting

How to read file names in the directory?

I am having n files in a directory i want to read all the file names from the script file .It is better if any one provide a sample script. Elaborating the scenario: i am having n number of sql files in a directory i am running all the sql files from a single script. sqlplus... (4 Replies)
Discussion started by: dineshmurs
4 Replies

7. Programming

How to read and write directory or file contents in c++ ?

Dear Friends, I m beginner unix programmer. I want to know, how to read and write directory or file contents in c++ ? (3 Replies)
Discussion started by: namrata5
3 Replies

8. Shell Programming and Scripting

Urgent!!!Read directory from a file

I have a receive script file which had lots of direcorties to process,but now,I don't want to hardcode them,I need input the directory name in a Property.txt file,then write shell code to read the directory name from Property.txt to the script file so I can get flexible on it.But when I ran the sh... (3 Replies)
Discussion started by: joshuaduan
3 Replies

9. UNIX for Dummies Questions & Answers

File/directory information......

Basically i have done created the script below, and it functions ok, it prints the access rights the user has. But i need it to print the group permissions, and other permissions, it would also be helpful if i could print the permissions in numeric form aswell, if it is possible. I have looked in... (50 Replies)
Discussion started by: Makaveli.2003
50 Replies
Login or Register to Ask a Question