On Thu, Jan 16, 2014 at 06:54 (-0500), E. Liddell wrote:
On Wed, 15 Jan 2014 19:11:56 -0600
"Darrell Anderson" <darrella(a)hushmail.com> wrote:
>>>> I would like to inspect source tree
text strings for instances
>>>> of KDE/kde rebranding issues and update to TDE/tde. Mostly in
>>>> tooltips and What's This help strings. My challenge is being
>>>> able to efficiently grep only those strings, which often in the
>>>> sources are multiple lines.
>>>> I would appreciate shell scripting
advice to find such text
>>>> strings.
>>> Nobody knows?
>>It would help to search whole words - grep
option '-w'?
> I don't understand how that helps. For
example, I want to find all
> TQWhatsThis strings, which often are multiple lines, and ensure I
> am searching the entire string, which includes all the multiple
> lines. About the only thing I know is the search will key on
> something like TQWhatsThis and the entire glob of text to search
> will end with an apostrophe (;). All of that constitutes the entire
> string that must be searched for 'KDE/kde'.
I think people may have misinterpreted your use of the
word "efficiently"
in the original post to mean that you had the basics worked out and
were just worried about the run time (I know I did).
I don't think you can do this with grep, which
operates primarily on
lines, unless you want to use shell script to read in each file and
concatenate the lines together without CR characters, then run grep
on the result. Much easier to forget about shell scripting and do it in
Perl, in which case you need to recurse across the directory tree,
slurp in entire files, run each through a regular expression match
like (from your example, and assuming you meant "semicolon" where
you wrote "apostrophe"):
/(TQWhatsThis.*?kde.*?\;)/gim
and print out the matches.
Darrell,
I'm not really clear on what it is you want to search for.
However, if the string that E. Liddell specifies is correct, you could
try this:
cd <top-level-dir-of-the-files-you-want-to-search>
find . -type f | while read f
do
if tr $'\n' ' ' < $f | sed 's/"[ \t][ \t]*"/ /g'
| grep -i 'TQWhatsThis[^"]*"[^"]*kde' >/dev/null
then
echo $f has it
fi
done
Explanation, in case it is needed:
- the find command produces a list of file which are fed into the
while loop
- the tr command turns newlines into spaces, so that
- the sed command glues adjacent strings together
- the grep finds
TQWhatsThis
followed by non-" stuff
followed by "
followed by KDE in any mixture of upper and lower case
- the if outputs the file name if grep found the string
There may be false alarms in this, but *off the top of my head* I
think it shouldn't miss anything, unless
- grep gets unhappy with files with very long lines, or
- someone has embedded double quotes, as in
TQWhatsThis ... ("blah \" blah KDE).
I am running it right now on my copy of the R14.0 tree on an i7-965
and I can say it is not blindingly fast.
The output I got (from a copy of the git tree from about 3 weeks ago) is:
./main/applications/kiosktool/kiosktool/kcms/autostart/kcmautostart.cpp has it
./main/applications/knowit/src/knowitpref.cpp has it
./main/applications/kasablanca/src/Q_generalpreferencesdialog.cpp has it
./main/applications/konversation/konversation/src/serverlistdialog.cpp has it
./main/tdelibs/tdeprint/management/kmconfigfonts.cpp has it
./main/tdelibs/tdeio/tdefile/kurlbar.cpp has it
./main/tdelibs/kate/part/katedialogs.cpp has it
./main/tdelibs/tdeui/kcursor.cpp has it
./main/tdelibs/tdeui/kwhatsthismanager.cpp has it
./main/tdelibs/tdecore/twin.cpp has it
./main/tdesdk/kbabel/kbabeldict/modules/tmx/preferenceswidget.cpp has it
./main/tdesdk/kbabel/kbabeldict/modules/pocompendium/preferenceswidget.cpp has it
./main/tdepim/korganizer/koattendeeeditor.cpp has it
./main/tdebase/klipper/configdialog.cpp has it
./main/tdebase/kcontrol/performance/system.cpp has it
./main/tdebase/kcontrol/konq/rootopts.cpp has it
./main/tdebase/kcontrol/kded/kcmkded.cpp has it
./main/tdebase/kcontrol/fonts/fonts.cpp has it
./main/tdebase/kcontrol/konqhtml/policydlg.cpp has it
./main/tdebindings/qtjava/javalib/qtjava/TQWhatsThis.cpp has it
./main/tdebindings/kalyptus/kalyptusDataDict.pm has it
./main/tdeadmin/lilo-config/kde-qt-common/images.cpp has it
./main/libraries/libtqt-perl/kalyptus/kalyptusDataDict.pm has it
./main/tdevelop/vcs/cvsservice/cvspart.cpp has it
./main/tdevelop/vcs/subversion/subversion_part.cpp has it
./main/tdevelop/parts/valgrind/valgrind_part.cpp has it
./main/tdevelop/parts/texttools/texttoolspart.cpp has it
./main/tdevelop/parts/tools/tools_part.cpp has it
./main/tdevelop/parts/diff/diffpart.cpp has it
./main/tdevelop/parts/outputviews/appoutputviewpart.cpp has it
./main/tdevelop/parts/outputviews/makeviewpart.cpp has it
./main/tdevelop/parts/fileview/filegroupspart.cpp has it
./main/tdevelop/parts/fileview/fileviewpart.cpp has it
./main/tdevelop/parts/fileview/partwidget.cpp has it
./main/tdevelop/parts/konsole/konsoleviewpart.cpp has it
./main/tdevelop/parts/fileselector/fileselector_widget.cpp has it
./main/tdevelop/parts/distpart/distpart_part.cpp has it
./main/tdevelop/parts/ctags2/ctags2_part.cpp has it
./main/tdevelop/parts/tipofday/tipofday_part.cpp has it
./main/tdevelop/parts/snippet/snippet_part.cpp has it
./main/tdevelop/parts/filelist/projectviewpart.cpp has it
./main/tdevelop/parts/filecreate/filecreate_part.cpp has it
./main/tdevelop/parts/filecreate/filecreate_widget2.cpp has it
./main/tdevelop/parts/filecreate/filecreate_widget3.cpp has it
./main/tdevelop/parts/grepview/grepviewpart.cpp has it
./main/tdevelop/parts/documentation/documentation_part.cpp has it
./main/tdevelop/buildtools/qmake/trollprojectwidget.cpp has it
./main/tdevelop/buildtools/autotools/autoprojectwidget.cpp has it
./main/tdevelop/buildtools/autotools/autoprojectpart.cpp has it
./main/tdevelop/kdevdesigner/designer/resource.cpp has it
./main/tdevelop/kdevdesigner/designer/mainwindow.cpp has it
./main/tdevelop/languages/ruby/debugger/debuggerpart.cpp has it
./main/tdevelop/languages/ruby/rubysupport_part.cpp has it
./main/tdevelop/languages/cpp/debugger/debuggerpart.cpp has it
./main/tdevelop/languages/bash/bashsupport_part.cpp has it
./main/tdevelop/languages/sql/sqlsupport_part.cpp has it
./main/tdevelop/languages/ada/adasupportpart.cpp has it
./main/tdevelop/embedded/visualboyadvance/visualboyadvance_part.cpp has it
I hope that helps. If it is not finding things it should, or it is
hitting you with too many false alarms, feel free to get back to me
with specifics and I may be able to help.
Jim