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

Hi all,

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.

I have updated the question RudiC

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.

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?