0

okay so i know of grep -rhi, which extrats the line if string is found, but I want to copy the entire file so for example,

file.txt >

isexample #new
iesameplxpele
ieamama #new

now if I used grep -rhi "#new", it would extract only

isexample #new
ieamama #new

where as I want all the contents within the file including

iesameplxpele

How would I do this?

Of course the .txt file must contain #new in either one of its lines.

1 Answers1

3

You have to check the return value of grep:

if grep -q '#new' "/path/to/inputfile"; then
  cp "/path/to/inputfile" "/location/of/outputfile"
fi
DopeGhoti
  • 76,081
ctx
  • 2,495