Showing posts with label grep. Show all posts
Showing posts with label grep. Show all posts

Saturday, December 15, 2012

grepping the smart way

Unfortunately WebLogic prints each log entry in multiple lines. This is a pain when you grep.

gawk will return the whole log entry:

gawk "BEGIN{RS=\"####\"}/BEA-000337/{print \$0}" *.log


When using grep, the option -A4 is handy to print a few extra lines (in the example, 4) after the ling matching the pattern:

grep -A4 BEA-000337 *





Saturday, July 31, 2010

Bash shell tricks

Tarring files recursively with filter

to create:
find . -name *.out | xargs tar cvf cohservernodes.tar

to append:
find . -name *.log | xargs tar rvf cohservernodes.tar

to list:
tar tf cohservernodes.tar


Find a text in files, recursively:

find . | xargs grep -s whatever



find and replace recursively

for file in $(grep -il "whatever" *.txt)
do
sed -e "s/Hello/Goodbye/ig" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
done

how about:

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *.html`

the above command works very well, but if you try

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *`

you get the error:

Can't do inplace edit: bla is not a regular file, <> line

because it tries to change also the directories

To do a find excluding directories you must do this (add -type f):

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name * -type f`