How to move the files to new directory based on names in text file?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have tar.gz
files like below in a directory df
:
A.tar.gz
B.tar.gz
C.tar.gz
D.tar.gz
E.tar.gz
F.tar.gz
G.tar.gz
I also have text file move.txt
with following columns information:
ID Status Status2 Status3 Status4 Status5 tar sample
ID1 Negative Negative Negative Negative Negative D.tar.gz Sam1
ID2 Negative Negative Negative Negative Negative A.tar.gz Sam2
ID3 Negative Negative Negative Negative Negative C.tar.gz Sam3
ID4 Negative Negative Negative Negative Negative F.tar.gz Sam4
I want to move files in directory df
to another directory based on their matching in move.txt
file
I tried this way but didn't work:
for file in $(cat move.txt)
do
mv "$file" ~/destination
done
Output should be in ~/destination
directory:
D.tar.gz
A.tar.gz
C.tar.gz
F.tar.gz
Looks like I'm missing the column in the text file. Any help?
linux files filenames text move
add a comment |Â
up vote
1
down vote
favorite
I have tar.gz
files like below in a directory df
:
A.tar.gz
B.tar.gz
C.tar.gz
D.tar.gz
E.tar.gz
F.tar.gz
G.tar.gz
I also have text file move.txt
with following columns information:
ID Status Status2 Status3 Status4 Status5 tar sample
ID1 Negative Negative Negative Negative Negative D.tar.gz Sam1
ID2 Negative Negative Negative Negative Negative A.tar.gz Sam2
ID3 Negative Negative Negative Negative Negative C.tar.gz Sam3
ID4 Negative Negative Negative Negative Negative F.tar.gz Sam4
I want to move files in directory df
to another directory based on their matching in move.txt
file
I tried this way but didn't work:
for file in $(cat move.txt)
do
mv "$file" ~/destination
done
Output should be in ~/destination
directory:
D.tar.gz
A.tar.gz
C.tar.gz
F.tar.gz
Looks like I'm missing the column in the text file. Any help?
linux files filenames text move
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have tar.gz
files like below in a directory df
:
A.tar.gz
B.tar.gz
C.tar.gz
D.tar.gz
E.tar.gz
F.tar.gz
G.tar.gz
I also have text file move.txt
with following columns information:
ID Status Status2 Status3 Status4 Status5 tar sample
ID1 Negative Negative Negative Negative Negative D.tar.gz Sam1
ID2 Negative Negative Negative Negative Negative A.tar.gz Sam2
ID3 Negative Negative Negative Negative Negative C.tar.gz Sam3
ID4 Negative Negative Negative Negative Negative F.tar.gz Sam4
I want to move files in directory df
to another directory based on their matching in move.txt
file
I tried this way but didn't work:
for file in $(cat move.txt)
do
mv "$file" ~/destination
done
Output should be in ~/destination
directory:
D.tar.gz
A.tar.gz
C.tar.gz
F.tar.gz
Looks like I'm missing the column in the text file. Any help?
linux files filenames text move
I have tar.gz
files like below in a directory df
:
A.tar.gz
B.tar.gz
C.tar.gz
D.tar.gz
E.tar.gz
F.tar.gz
G.tar.gz
I also have text file move.txt
with following columns information:
ID Status Status2 Status3 Status4 Status5 tar sample
ID1 Negative Negative Negative Negative Negative D.tar.gz Sam1
ID2 Negative Negative Negative Negative Negative A.tar.gz Sam2
ID3 Negative Negative Negative Negative Negative C.tar.gz Sam3
ID4 Negative Negative Negative Negative Negative F.tar.gz Sam4
I want to move files in directory df
to another directory based on their matching in move.txt
file
I tried this way but didn't work:
for file in $(cat move.txt)
do
mv "$file" ~/destination
done
Output should be in ~/destination
directory:
D.tar.gz
A.tar.gz
C.tar.gz
F.tar.gz
Looks like I'm missing the column in the text file. Any help?
linux files filenames text move
edited Apr 27 at 13:04
Kiwy
5,30743350
5,30743350
asked Apr 27 at 11:36
beginner
355
355
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
bash
+ awk
solution:
for f in $(awk 'NR > 1 print $7 ' move.txt); do
[[ -f "$f" ]] && mv "$f" ~/destination
done
Or with xargs
:
awk 'NR > 1 print $7 ' move.txt | xargs -I echo mv ~/destination
The crucial awk
operation implies:
NR > 1
- start processing from the 2nd line (skip the 1st one as header)print $7
- print the 7th field value$7
(tar
column)
add a comment |Â
up vote
2
down vote
Answering my own question
Inside directory "df" I gave the following command. And it worked.
cat move.txt | xargs mv -t destination/
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
bash
+ awk
solution:
for f in $(awk 'NR > 1 print $7 ' move.txt); do
[[ -f "$f" ]] && mv "$f" ~/destination
done
Or with xargs
:
awk 'NR > 1 print $7 ' move.txt | xargs -I echo mv ~/destination
The crucial awk
operation implies:
NR > 1
- start processing from the 2nd line (skip the 1st one as header)print $7
- print the 7th field value$7
(tar
column)
add a comment |Â
up vote
2
down vote
accepted
bash
+ awk
solution:
for f in $(awk 'NR > 1 print $7 ' move.txt); do
[[ -f "$f" ]] && mv "$f" ~/destination
done
Or with xargs
:
awk 'NR > 1 print $7 ' move.txt | xargs -I echo mv ~/destination
The crucial awk
operation implies:
NR > 1
- start processing from the 2nd line (skip the 1st one as header)print $7
- print the 7th field value$7
(tar
column)
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
bash
+ awk
solution:
for f in $(awk 'NR > 1 print $7 ' move.txt); do
[[ -f "$f" ]] && mv "$f" ~/destination
done
Or with xargs
:
awk 'NR > 1 print $7 ' move.txt | xargs -I echo mv ~/destination
The crucial awk
operation implies:
NR > 1
- start processing from the 2nd line (skip the 1st one as header)print $7
- print the 7th field value$7
(tar
column)
bash
+ awk
solution:
for f in $(awk 'NR > 1 print $7 ' move.txt); do
[[ -f "$f" ]] && mv "$f" ~/destination
done
Or with xargs
:
awk 'NR > 1 print $7 ' move.txt | xargs -I echo mv ~/destination
The crucial awk
operation implies:
NR > 1
- start processing from the 2nd line (skip the 1st one as header)print $7
- print the 7th field value$7
(tar
column)
edited Apr 27 at 12:03
answered Apr 27 at 11:58
RomanPerekhrest
22.4k12144
22.4k12144
add a comment |Â
add a comment |Â
up vote
2
down vote
Answering my own question
Inside directory "df" I gave the following command. And it worked.
cat move.txt | xargs mv -t destination/
add a comment |Â
up vote
2
down vote
Answering my own question
Inside directory "df" I gave the following command. And it worked.
cat move.txt | xargs mv -t destination/
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Answering my own question
Inside directory "df" I gave the following command. And it worked.
cat move.txt | xargs mv -t destination/
Answering my own question
Inside directory "df" I gave the following command. And it worked.
cat move.txt | xargs mv -t destination/
answered Apr 27 at 12:05
beginner
355
355
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440398%2fhow-to-move-the-files-to-new-directory-based-on-names-in-text-file%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password