find cont'd 3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Another question about find.  I looked at the gnome tool and tried to 
simulate what it is doing.  I can't use it directly because it won't
do sed.  Basically I want to find all files with a string (except binary)
and change it.  let STR be the string I am looking for.  NEW is new string.
I am doing

TFIL=/usr/tmp/dummy$$.txt
find . -type f | while read fil
do
     grep "$STR" $fil > $TFIL
     [ $? -eq 0 ] || continue      ## does not match

     if [ "$(cat $TFIL)" = "Binary file $fil matches" ]
     then
          continue    # Don't operate on binary files
     fi

     sed -i "s/$STR/$NEW/g" $fil
done

(I will have to do something with sed in case there is "/" in the string)

Problem is, the grep redefines my stdin so it no longer comes from
the list of files that "find" found, and it then terminates after finding
the first file.

Anyway to "push" stdin on the stack or something before the grep,
and "pop" it again afterwards, so it goes back to the list of files found?


_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux