Copying filenames into a new file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying filenames into a new file
# 1  
Old 05-25-2011
Copying filenames into a new file

I have about 35,000 files in one directory. Here I have to write a ksh to take only the filenames of 500 files at a time and put them into a new file. Can anyone please help me.

Thank you.
# 2  
Old 05-25-2011
Do you mean you wanna move the content of 500 files into one file, then the content of the 500 next files into another file etc until no more files left ?
# 3  
Old 05-25-2011
I do not have to move the content of the files but only have to write first 500 file names into one file, then the next 500 file names into another file etc until no more file were found.

Thank you.
# 4  
Old 05-25-2011
Ok
Then something like that ?
Code:
ls | split -dl 500 - /tmp/file-list-

# 5  
Old 05-25-2011
Quote:
Originally Posted by Chirel
Ok
Then something like that ?
Code:
ls | split -dl 500 - /tmp/file-list-


For some reason its throwing error as
Code:
 split: illegal option -- d

so i modified it by removing d and its working
Code:
 
ls | split -l 500 - /tmp/file-list-

It is just writing the filenames, so what should i do inorder to get the filenames along with there path.

Thank you.
# 6  
Old 05-25-2011
Maybe with -f ?
# 7  
Old 05-25-2011
If I use -f I am getting an error as below:
Code:
split: Not a recognized flag: f
Usage: split [-l Line_Count] [-a Suffix_Length] [File [Prefix]]
   or: split -b Number[k|m] [-a Suffix_Length] [File [Prefix]]

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 take the filenames from a directory and store into a file??

hi, how can i take the file names from a directory and store only the filenames in the file. suppose i have a directory which contains the following files and subdirectories. $ ls -ltr total 16 -rw-rw-r-- 1 adm etc 4 Aug 6 20:37 s1.txt -rw-rw-r-- 1 adm etc 4 Aug 6 20:37 s2.txt... (11 Replies)
Discussion started by: Little
11 Replies

2. Shell Programming and Scripting

print all filenames in directory with path to another file

hi, i have a directory at /path/unix with the following files 1.txt 2.txt 3.txt 4.txt I want to make another file called filenames.txt at a different location called /path/home. So, my output file would be /path/home/filenames.txt with contents /path/unix/1.txt... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

3. 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

4. UNIX for Dummies Questions & Answers

Searching for a pattern from filenames stored in a file

Hi, I have got some 10 filenames stored in a file or displayed in the console as a result of some query i made.. Now I need to open each of these files and search for a pattern in these 10 files.. Can someone help me with this? Thanks, Jean (9 Replies)
Discussion started by: jeanjkj
9 Replies

5. UNIX for Dummies Questions & Answers

Capture filenames with a Pattern into another file

Hi i have a command in windows which captures the filenames with the same pattern and route it to another file. for example filetest_20110921, filetest_20110922,filetest_20110923 etc I would like to know the command in UNIX/LINUX for the same. The command which i am using in Windows is ... (12 Replies)
Discussion started by: mansurkhalil
12 Replies

6. AIX

How to grep filenames from a file in other files?

Hi, We have a file called applcust.txt where we keep records of our customizations in the following format. We want to verify whether the file, which is in 3rd column in this file is there in another file called patch999999.log to find out if any of our customization has got overwritten by the... (2 Replies)
Discussion started by: sshah1001
2 Replies

7. Programming

Sort the filenames containing . in file name

Hi All, I have a list of files in a directory ..which are look like: 42420031.1000 42420031.1001 42420031.396 42420031.402 42420031.403 42420031.404 42420031.405 42420031.406 42420031.407 42420031.408 42420031.409 Here when i do ls 42420031* |sort it gives the output as ... (3 Replies)
Discussion started by: sanj_eck
3 Replies

8. Shell Programming and Scripting

bash: reading filenames from file

Hi, I'm trying to write a script that reads filenames from a file and use these filenames in a loop. The filenames are all on one line and the problem is that these filenames have wildcards like * and braces like in them. Right now what I'm doing is something like this: echo "reading from... (0 Replies)
Discussion started by: warp17
0 Replies

9. Shell Programming and Scripting

Grepping for filenames containing value in specific segment within file

I am trying to grep for filenames containing a specific value within a particular segment. The lines containing the segment I'm looking through reads like "HL^1^^1^1", "10^9^9^0", and "HL^11^4^8^1". I would like to find the data that contains only the number nine after the third caret where the... (4 Replies)
Discussion started by: HLee1981
4 Replies

10. UNIX for Advanced & Expert Users

Sorting filenames by order in another file

I would like to arrange /sort filenames ending with suffix like ".00XXXX". where X is a digit. However the order of arrangement is in a text file and is 'harpharzard'. e.g the text file may be like 002345 009807 001145 I wanted to avoid doing this using sql and exporting the text file back to... (4 Replies)
Discussion started by: samudimu
4 Replies
Login or Register to Ask a Question