Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Grep command to find files containing text string and move them

Status
Not open for further replies.

jikwle

Newbie
Newbie level 1
Joined
Jan 25, 2022
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
8
I am able to locate files in a folder containing a specific text string using this command:
grep -lir 'string' ~/directory/*
How do I move the files that appear in the above result to another location?
 

Hi,

I´m really not experienced with Linux ... thus I just have a quick and dirty solution:

* first do the GREP and write it´s results in a file
* then do the MOVE according the file contents

But I guess there is a more elegant solution....

Klaus
 

Hi,

I´m really not experienced with Linux ... thus I just have a quick and dirty solution:

* first do the GREP and write it´s results in a file
* then do the MOVE according the file contents

But I guess there is a more elegant solution....

Klaus
That's what I do, grep into a file of targets and then vi the
file to make clean 'mv' commands. Though if you understood
the output of the grep you might pipe the stream to 'sed -e'
with similar sytnax, I prefer having the chance to correct any
fat-fingering along the way.
 

* first do the GREP and write it´s results in a file
* then do the MOVE according the file contents
I guess this is the only solution but you can use pipes and /or sed to give a professional look.

But if the numbers are small and you need to do it only once, it is better to do as KlausST says.

Do check visually after every step just to make sure you know what you are doing and what you want.
 

If you use a file as the intermediate medium and visually check before doing the 'move' then that will not encounter this problem.
However if you use as pipe (which means that the processes might run in parallel), make sure that the move destination is either not scanned by the 'grep' or scanned before the 'move' into that destination from somewhere else.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top