How to create multiple list of files in a directory ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to create multiple list of files in a directory ?
# 1  
Old 06-11-2009
How to create multiple list of files in a directory ?

Hi,

i have say 100 files in a directory.

file1.log
file2.log
file3.log
file4.log
file5.log
file6.log
...
...
...
file99.log
file100.log
=========
I need to create another file which contains the list of al these log files.
each file should contain only 10 log file names.
it shud be like

filename1.list --- can contain first 10 log file, may be based on the timestamp.

filename2.list --- next 10 files.

So since we have 100 log files in this location, we need to get 10 filename*.list with 10 files in each file..


Did i confuse with the question? please let know Smilie

Please help

Regards,
Robz
# 2  
Old 06-11-2009
Logic

Hello,

Here is a logic that you can use. Try to implement it and ask if you have problems constructing the statements.

1. List al the log filenames.
2. add the names to an array.
3. loop through the array writing 10 records to a file
4. change filename when 10 records are written

Regards,
HKansal
# 3  
Old 06-12-2009
thanks bro.. but am writing a Shell script for this..

Array seems not possible...

u got any code snippet

Regards,
Robin Paulose
# 4  
Old 06-12-2009
somewhat like this can work...modify it if u need...
Code:
set -A _Array `ls file*`
i=0
j=10
for file_name in ${_Array[@]}
do
   if [[ $j -eq 10 ]]; then
      j=0;
      (( i = $i + 1 ))
      >filename$i.list
   fi
   echo $file_name >> filename$i.list
   (( j = $j + 1 ))
done

# 5  
Old 06-12-2009
Bug code

Here I would say "good job Rakesh" as you captured the logic I stated earlier.

But I would have considered it better to give that step wise. Anyways, the job's done I guess.

Regards,
HKansal
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

2. Shell Programming and Scripting

How Create new directory and move files to that directory.?

Hi All, We have main directory called "head" under this we have several sub directories and under these directories we have sub directories. My requirement is I have to find the SQL files which are having the string "procedure" under "head" directory and sub directories as well. And create... (14 Replies)
Discussion started by: ROCK_PLSQL
14 Replies

3. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

4. Shell Programming and Scripting

Create multiple zip files each containing 50 xml files.

Hi, Is there a direct command or need to write a shell script for following requirement? Everyday a folder is populated with approx 25k to 30k xml files. I need to create multiple zip files in the same folder each containing 50 xml files. The last zip file may or may not contain 50 xml files.... (6 Replies)
Discussion started by: Rakesh Thobula
6 Replies

5. Shell Programming and Scripting

Create Multiple UNIX Files for Multiple SQL Rows output

Dear All, I am trying to write a Unix Script which fires a sql query. The output of the sql query gives multiple rows. Each row should be saved in a separate Unix File. The number of rows of sql output can be variable. I am able save all the rows in one file but in separate files. Any... (14 Replies)
Discussion started by: Rahul_Bhasin
14 Replies

6. UNIX for Dummies Questions & Answers

Need help how to create a file (xml) list all files from directory

I have more than 10K songs in two directories on a hard drive. I would like to create a file list all of files name then change to .xml extension to upload to iPhone so I have a Karaoke list on my iPhone. I need your help to create a file by using command in Linux. Files names: 0001 More... (4 Replies)
Discussion started by: ggcc
4 Replies

7. Shell Programming and Scripting

[Solved] how to create multiple directory in one mkdir command

Hi, Unix Gurus, - I have a simple question, I need create multiple directory. I use mkdir {dir1, dir2, dir3) I got one directory as {dir1, dir2, dir3} I searched @ google, I got answer as above code.:wall::confused: Anybody has any idea Thanks in advance ---------- Post updated... (3 Replies)
Discussion started by: ken002
3 Replies

8. Shell Programming and Scripting

Create a list of directory contents

Well I did a search and didn't anything for my specific case. I got a directory with a bunch of text file. All of them have the following pattern on the filename "ABCD_<As of Date>.txt" Example: ABCD_20110301.txt ABCD_20110302.txt ABCD_20110303.txt All I want to accomplish is a Korn... (3 Replies)
Discussion started by: Shark Tek
3 Replies

9. Shell Programming and Scripting

Create variables from directory list problem

I am trying to take a list of directories in a folder and give them a variable name. I have this working with the exception that the shell_exec command wants to place a return. Here is my code which might explain better what I am trying to do: <?php session_start(); $student1=$_SESSION;... (0 Replies)
Discussion started by: robp2175
0 Replies
Login or Register to Ask a Question