Forum Stats

  • 3,815,185 Users
  • 2,258,973 Discussions
  • 7,892,982 Comments

Discussions

how to copy the grep results to a folder

Tony007
Tony007 Member Posts: 4,224 Bronze Trophy

hi i have the following

grep -i "textword" *.*

i what the return results to be copy to a folder i what the files which meet this to be copy to a folder how can i do this am in oracle linux

Answers

  • philfry
    philfry Member Posts: 11 Green Ribbon

    Hi,

    don't know if I got this right, but what about

    grep -l "textword" *.* | xargs -r -d '\n' -i mv "{}" /path/to/dir

    grep: -l returns the filename instead of the matching line

    xargs: -r means "don't run if there are no results", -d '\n' sets the input delimiter to newline, -i means "replace {} with the input line".