Search code examples
linuxbashforeachmv

In Bash move files to location, from 2 text files


I have a list of files in a text file, one per line, and another text file with the corresponding locations to move the files, one per line.

How can I execute in bash (mv file on (text file1 line 1) to location (on line 1 of text file2))?


Solution

  • Read from each file separately:

    while read file1; read file2 <&3; do
       mv -- "$file1" "$file2"
    done < file1.txt 3< file2.txt