ehrid
ehrid

Reputation: 125

How to move files based on file (file name and location in file)

I tried but I failed, I have file like:

06faefb38081b44e35b4ee846bfb84b61694a5c4.zip D:/code/3635/
0a386c77a3ae35033006efec07bfc37f5236212c.zip D:/code/3622/
0b425b29c3e51f29b9af03db46df0aa8f726705b.zip D:/code/3624/
0ecb477c82ec540c8eb0642da144a400bbf3f7c0.zip D:/code/3624/
...

My goal is to move file in first column to location in second column. I tried with while+awk but this did not worked. I would appreciate any help!

Upvotes: 0

Views: 423

Answers (3)

Kent
Kent

Reputation: 195229

What you need is just add a mv (space) to the beginning of each line. So you have 100+ ways to do that. If you love awk:

awk '$1="mv "$1' file

will create the mv command, to execute them, you can:

 awk '$1="mv "$1' file |sh

I prefer this than the system() function call.

Upvotes: 0

Sergius
Sergius

Reputation: 986

Let's assume, you file has name "data.txt", thus your code might look like this:

while read line; do mv $line; done < data.txt

Upvotes: 1

Raman Sailopal
Raman Sailopal

Reputation: 12917

awk '{ system("mv "$1" "$2) }' filename

With awk, you can use the system function to build a move command and excute it. Obviously ensure that you are running the command in the directory with the files.

Upvotes: 3

Related Questions