looping thru filenames in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting looping thru filenames in a directory
# 1  
Old 07-02-2008
looping thru filenames in a directory

Hi,

i am very new to UNIX, i am trying to loop thru the files in a directory.

I got the filenames into a variable using

$files=`ls`

Here $files will contain

<filename1> <filename2> <filename3>

I want to get one filename at a time and append it to some some text.

forexample,
text1\filename1
text1\filename2
text1\filename3

Any idea hw i can do this?
# 2  
Old 07-02-2008
Quote:
Originally Posted by silas.john
Hi,

i am very new to UNIX, i am trying to loop thru the files in a directory.

I got the filenames into a variable using

$files=`ls`

Here $files will contain

<filename1> <filename2> <filename3>

I want to get one filename at a time and append it to some some text.

forexample,
text1\filename1
text1\filename2
text1\filename3

Any idea hw i can do this?
Smilie
Code:
files=`find . -type f`

for simplefiles in $files
  do
     echo $simplefiles >> what u want to do
  done

Thanks
Namish

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get filenames in a directory and write them in to a file?

I need to get the names of files which are starting with a string testfile. Also i want to create a XML file in the same location and write these file names into the XML. Ex: <path> <dir> <file>testfile1</file> </dir> <dir> <file>testfile2</file> </dir>... (4 Replies)
Discussion started by: vel4ever
4 Replies

2. UNIX for Dummies Questions & Answers

Filenames change in a directory

Hi I have abc_ahb_one.v abc_ahb_two.v abc_ahb_three.v ........l like this -----upto abc_ahb_ninety.v in some directory. I need to change those file names to like below. ... (5 Replies)
Discussion started by: praneethk
5 Replies

3. Shell Programming and Scripting

Getting filenames from a directory in single line

Hi All, I have a requirement where I need to get the all file names present in a particular directory in to a single separated by space, I have files in /home/RAAM/work directory as test1.xls test2.xls test3.xls I need to get all filenames from that directory in single line like ... (6 Replies)
Discussion started by: Raamc
6 Replies

4. Shell Programming and Scripting

Use filenames to create directory.

I have many files similar to this one: AC41_AC85_86_AC128_129_MC171_173_SF_207_FMV.pdf. I want a directory named AC41 and to put the file AC41_AC85_86_AC128_129_MC171_173_SF_207_FMV.pdf into the directory. Next, a directory named AC85 and put the file into it. Also, continue to cycle through... (1 Reply)
Discussion started by: ndnkyd
1 Replies

5. Shell Programming and Scripting

Change all filenames in a directory

I have a directory of files and each file has a random 5 digit string at the beginning that needs to be removed. Plus, there are some files that will be identically named after the 5 digit string is removed and I want those eliminated or moved. any ideas? (17 Replies)
Discussion started by: crumb
17 Replies

6. Shell Programming and Scripting

Looping through filenames with spaces

I need to loop through the files in a directory and process the files. But some of the filenames contain spaces. Here is a little test script I've been using to experiment. (I'm not really going to call 'echo', I'm doing some other processing.) Everything I try fails. How can I do this??... (7 Replies)
Discussion started by: KenJackson
7 Replies

7. Shell Programming and Scripting

concatenating the filenames in a directory

hi all, I have a requirement where in i have to read all the filenames based on a pattern from a directory and concatenate all these file names and write it to another file. i am using the following code to do this var1='' for filename in $_DIR/${FILE_NAME}* do if if then... (7 Replies)
Discussion started by: nvuradi
7 Replies

8. Shell Programming and Scripting

running a looping script for all files in directory

I have three different linux command scripts that I run for 20+ files in one directory. it goes like this FIRST SCRIPT: grep 'something' -w file > newfile1 . . . grep 'something -w file > newfile20 then I take all these 'newfileN' and run this: awk 'BEGIN {... (20 Replies)
Discussion started by: labrazil
20 Replies

9. Shell Programming and Scripting

Looping through the directory

Hi, I have to write a KSH script to loop through the directory and transfer all the files through FTP. The source machine is the Network shared drive and the files in the directory needs to be FTPied to the UNIX server. For eg. Directory (Datasource) + Directory1 ... (6 Replies)
Discussion started by: mahalakshmi
6 Replies

10. Shell Programming and Scripting

rm files in a directory, looping, counting, then exit

I am trying to write a script that will look for a file in a directory, then remove it. I need it to loop until it has removed a certain number of files. Is it better to do a repeat or to list each file in a pattern? Files will be numbered like RAF.01.*, RAF.02.*, etc. Thanks, James (6 Replies)
Discussion started by: JporterFDX
6 Replies
Login or Register to Ask a Question