Search code examples
shellsolaris

In Solaris, I need to move a file, name of which is in a filelist


This is in Solaris. Please note, i am a novice in shell scripting. So request for some assistance.

I have a filelist with a filename(just a single filename). I need to move the file from one directory to another directory, by reading this filelist.

I need a command to do it.

To add something like below, where filelist.txt contains a filename and the file is in the source path /path and i need to move it to a different path /path2/dest

mv /path/ 'cat filelist.txt' /path2/dest/


Solution

  • You're close. Instead of 'cat filelist.txt, you need to make it a subshell. Assuming you're sh compatible, this should work:

    mv /path/$(cat filelist.txt) /path2/dest/
    

    If you want to support multiple files however, a simple loop would do the trick.

    cat filelist.txt | while read f; do
        mv /path/${f} /path2/dest
    done