0

I have a single file which contains source file paths and destination file paths.

example

$ cat test.txt
/home/data/source.txt   /home/code/destination.txt
/home/abc/def.txt   /home/mnp/xyz.txt

Here i want to copy /home/data/source.txt to /home/code/destination.txt (cp /home/data/source.txt /home/code/destination.txt)

I have so many source path and Destination path in a single file

So I want a command by which I can copy file from source path to destination path.

Thanks.

1

Here's an idea:

  • make a copy of your file: cp test.txt test.sh
  • put cp at the beginning of each line: sed -i 's/^/cp / test.sh
  • make the file executable: chmod +x test.sh
  • execute the file: ./test.sh
1
cat test.txt | xargs -L 1 cp -v

where:

  • test.txt is your input file
  • xargs -L 1 will list lines one by one and run
  • cp is the copy command
  • -v is there to have visibility and for check

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.