I
I
IvanSerr2020-09-25 16:31:14
linux
IvanSerr, 2020-09-25 16:31:14

How to copy the contents of a file after a GREP search?

How can I make grep recursively search ( grep -R "sometext" /some/path ) copy the entire contents of each file by finding an entry into another single file?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lesha, 2020-09-25
@IvanSerr

grep -lR "sometext" /some/path | xargs cat >> somefile.txt

If it finds sometext in a file, it will copy all its contents to somefile.txt

D
Dmitry, 2020-09-25
@q2digger

any_command >> other-file

P
pfg21, 2020-09-25
@pfg21

for loop on exhaust grep bash for grep
redirect grep exhaust to xargs, which will parse the list and apply commands to them bash grep xargs
study - there is everything on the Internet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question