Skip to main content
Post Reopened by Stéphane Chazelas find
Post Closed as "Duplicate" by Stéphane Chazelas find
added 14 characters in body
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

I have many files in a SRC folder. I would like to move all the files that follow a particular pattern from this SRC folder to another DST folder along with rename the file with a required extension.

Sample Parameters

SRC directory /Vinodh/Vinodh

Files in /Vinodh/Vinodh folder are TEST01TEST01, TEST02TEST02, TEST03TEST03, TEST04TEST04

TEST02 & TEST03 containsTEST02 & TEST03 contain the word WORLDWORLD

DST directory /TEST/TEST

I want theto move the TEST02TEST02 & TEST03 fileTEST03 files to /TEST/TEST folder as TEST02.txtTEST02.txt and TEST03.txtTEST03.txt

iI will be typing the command as

cd /Vinodh

grep -l 'WORLD' TEST

mv TEST02 /TEST

mv TEST03 /TEST

cd /TEST

mv TEST02 TEST02.txt

mv TEST03 TEST03.txt

cd /Vinodh
grep -l 'WORLD' *TEST*
mv TEST02 /TEST
mv TEST03 /TEST
cd /TEST
mv TEST02 TEST02.txt
mv TEST03 TEST03.txt

I wantI'd like to combine all this to a single line statement or i want ahave batch file that copies all the files in a single shot.

I have many files in a SRC folder. I would like to move all the files that follow a particular pattern from this SRC folder to another DST folder along with rename the file with a required extension.

Sample Parameters

SRC directory /Vinodh

Files in /Vinodh folder are TEST01, TEST02, TEST03, TEST04

TEST02 & TEST03 contains the word WORLD

DST directory /TEST

I want the move the TEST02 & TEST03 file to /TEST folder as TEST02.txt and TEST03.txt

i will be typing the command as

cd /Vinodh

grep -l 'WORLD' TEST

mv TEST02 /TEST

mv TEST03 /TEST

cd /TEST

mv TEST02 TEST02.txt

mv TEST03 TEST03.txt

I want to combine all this to a single line statement or i want a batch file that copies all the files in a single shot.

I have many files in a SRC folder. I would like to move all the files that follow a particular pattern from this SRC folder to another DST folder along with rename the file with a required extension.

Sample Parameters

SRC directory /Vinodh

Files in /Vinodh folder are TEST01, TEST02, TEST03, TEST04

TEST02 & TEST03 contain the word WORLD

DST directory /TEST

I want to move the TEST02 & TEST03 files to /TEST folder as TEST02.txt and TEST03.txt

I will be typing the command as

cd /Vinodh
grep -l 'WORLD' *TEST*
mv TEST02 /TEST
mv TEST03 /TEST
cd /TEST
mv TEST02 TEST02.txt
mv TEST03 TEST03.txt

I'd like to combine all this to a single line statement or have batch file that copies all the files in a single shot.

Source Link

find Command along with grep and mv

I have many files in a SRC folder. I would like to move all the files that follow a particular pattern from this SRC folder to another DST folder along with rename the file with a required extension.

Sample Parameters

SRC directory /Vinodh

Files in /Vinodh folder are TEST01, TEST02, TEST03, TEST04

TEST02 & TEST03 contains the word WORLD

DST directory /TEST

I want the move the TEST02 & TEST03 file to /TEST folder as TEST02.txt and TEST03.txt

i will be typing the command as

cd /Vinodh

grep -l 'WORLD' TEST

mv TEST02 /TEST

mv TEST03 /TEST

cd /TEST

mv TEST02 TEST02.txt

mv TEST03 TEST03.txt

I want to combine all this to a single line statement or i want a batch file that copies all the files in a single shot.