How do I custom sort the files in a directory using the filenames in a text file.?

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How do I custom sort the files in a directory using the filenames in a text file.?
# 1  
Old 02-15-2017
How do I custom sort the files in a directory using the filenames in a text file.?

Hi all,

Last edited by KMusunuru; 02-17-2017 at 02:18 PM.. Reason: Added CODE tags
# 2  
Old 02-15-2017
Why don't you post your for loop and the logics (what do you mean with "merge"?) you want applied to your files so we can decently help you?
If concatenating the files together with cat were the goal, would this come close?
while read FN; do echo cat "$FN >> resultfile"; done <file1
cat /home/k/abc.txt >> resultfile
cat /home/k/xyz.txt >> resultfile
cat /home/k/pqr.txt >> resultfile

Remove the echo and requote if happy with the result.

Last edited by RudiC; 02-15-2017 at 05:54 PM..
# 3  
Old 02-15-2017
I have updated the question RudiC
# 4  
Old 02-15-2017
What does "sort the files based on the order in file1.txt" mean? Cramming it inside a block of pseudocode does not clarify it, since the pseudocode has nothing to do with it. Neither does your statement of "merge" earlier. Which is it?

What output are you expecting, from your input?

If you were sorting by running commands by hand, what commands would you be running in what order? Show what you want your program to be doing based on what input. Some really example input and output files would help.
# 5  
Old 02-15-2017
That is the place where I need some code to work out the process. I need the resultant csv files merged at the last . but first I need some sorting process to work it out
# 6  
Old 02-15-2017
Originally Posted by KMusunuru
That is the place where I need some code to work out the process. I need the resultant csv files merged at the last . but first I need some sorting process to work it out
No. It is not. What you need here is to clearly describe what you are trying to do. You have file1.txt and you have a bunch of files in the current working directory with names matching the final component of the pathnames given in file1.txt. Why do you need to sort anything? If you have a list of files to process and a bunch of files in the current directory, why not just read you list of files and process them in the order in which they appear in file1.txt?

What output(s) is(are) your script supposed to produce?

Is this a homework assignment?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort file data according to a custom list of string

I have a string of pre defined ip address list which will always remain constant their order will never change like in below sample: iplist=,,,,144.1.113 In the above example i m considering only 5 ips but there could be many more. Now i have a file which... (15 Replies)
Discussion started by: mohtashims
15 Replies

2. Shell Programming and Scripting

Add filenames to top of each files in a directory

Hello, I tried different solutions given in various linux portals but no luck.. The directory consists of files with no-extension. Each file has only one line. I need to add each filename to the top of each file so eventually each file will have two rows. Filenames have spaces between words... (6 Replies)
Discussion started by: baris35
6 Replies

3. Shell Programming and Scripting

Sort and Split file with header and custom name

Hi, I am using SUN SOLARIS (SunOS sun4v sparc SUNW, T5240). I have a huge data file with header and trailer. This file gets used into an ETL process. ETL skips the header record (which is the first record of the file) and loads the rest of the record. The file can be delimited (comma,... (5 Replies)
Discussion started by: Saanvi1
5 Replies

4. Shell Programming and Scripting

There are multiple filenames in the directory.How to return the the lastest files for each file name

there are mutiple file nams in the directory. How to return the the lastest files for each file name. ex. abc1234_050201 abc1234_050206 abc1234_050208 xyz34_050204 xyz34_050210 xyz34_050218 thanks (4 Replies)
Discussion started by: grand_sam
4 Replies

5. UNIX for Dummies Questions & Answers

How to create a TAR File in a Custom Destination Directory?

I want to create the tarzip file into a destination directory, i am in /var/sftp/home/archive/rquadri directory and i am using below command. However it is creating the file in the /var/sftp/home/archive/rquadri directory itself instead of /tmp, may i please know how do i resolve this. tar -cvzf... (5 Replies)
Discussion started by: Ariean
5 Replies

6. UNIX for Dummies Questions & Answers

using gsed with cp to sort files in directory - every N file copy to new place

Hi all, I'm having a problem with some basic piping issues... I have been able to get in a directory and ls | gsed in order to list every N file for instance: ls | gsed -n '2~5p' The thing is I want to be able to copy the output files to a new directory. Basically directory /all has a... (4 Replies)
Discussion started by: dgoss
4 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

Shellscript to sort duplicate files listed in a text file

I have many pdf's scattered across 4 machines. There is 1 location where I have other Pdf's maintained. But the issues it the 4 machines may have duplicate pdf's among themselves, but I want just 1 copy of each so that they can be transfered to that 1 location. What I have thought is: 1) I have... (11 Replies)
Discussion started by: deaddevil
11 Replies

9. Shell Programming and Scripting

read list of filenames from text file and remove these files in multiple directories

I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like... (5 Replies)
Discussion started by: fxvisions
5 Replies

10. AIX

loop through the directory for files and sort by date and process the first file

hello i have a requirement where i have a direcotry in which i get files in the format STOCKS.20080114.dat STOCKS.20080115.dat STOCKS.20080117.dat STOCKS.20080118.dat i need to loop through the directory and sort by create date descending order and i need to process the first file. ... (1 Reply)
Discussion started by: dsdev_123
1 Replies
Login or Register to Ask a Question

Featured Tech Videos