user1586243
user1586243

Reputation: 51

UNIX - need help in grep command

I am trying to change the copyrights in a repository, i mean change the old copyrights to new copyrights for example copyrights 2008 to copyrights 2012,

so what i want to do is to find,

  1. How many files have 2 copyrights
  2. How many files do not have any copyrights in them
  3. How many files have single, old copyrights in them

I was able to achieve questions 2 by using grep -vir copyright *, and question 3 by using grep -rni copyright *

how do I list out all the files with 2 copyrights in them?

Upvotes: 1

Views: 360

Answers (3)

Jonathan Leffler
Jonathan Leffler

Reputation: 753465

Presumably 3, 4, or more copyrights are as troublesome as 2?

You can use grep to count, and then again to filter out the counts of 1:

grep -irc copyright * | grep -v '^ *1 '

Upvotes: 2

nrz
nrz

Reputation: 10550

Use xargs to get the number of copyright lines for all files:

ls * | xargs -I % sh -c "echo %; grep -c 'copyright' %"

Upvotes: 0

Ed Heal
Ed Heal

Reputation: 59987

Use uniq with the -c flag. i.e. grep copyright * | uniq -c | egrep -v '^1'

Upvotes: 0

Related Questions