DEVTOME.COM HOSTING COSTS HAVE BEGUN TO EXCEED 115$ MONTHLY. THE ADMINISTRATION IS NO LONGER ABLE TO HANDLE THE COST WITHOUT ASSISTANCE DUE TO THE RISING COST. THIS HAS BEEN OCCURRING FOR ALMOST A YEAR, BUT WE HAVE BEEN HANDLING IT FROM OUR OWN POCKETS. HOWEVER, WITH LITERALLY NO DONATIONS FOR THE PAST 2+ YEARS IT HAS DEPLETED THE BUDGET IN SHORT ORDER WITH THE INCREASE IN ACTIVITY ON THE SITE IN THE PAST 6 MONTHS. OUR CPU USAGE HAS BECOME TOO HIGH TO REMAIN ON A REASONABLE COSTING PLAN THAT WE COULD MAINTAIN. IF YOU WOULD LIKE TO SUPPORT THE DEVTOME PROJECT AND KEEP THE SITE UP/ALIVE PLEASE DONATE (EVEN IF ITS A SATOSHI) TO OUR DEVCOIN 1M4PCuMXvpWX6LHPkBEf3LJ2z1boZv4EQa OR OUR BTC WALLET 16eqEcqfw4zHUh2znvMcmRzGVwCn7CJLxR TO ALLOW US TO AFFORD THE HOSTING.

THE DEVCOIN AND DEVTOME PROJECTS ARE BOTH VERY IMPORTANT TO THE COMMUNITY. PLEASE CONTRIBUTE TO ITS FURTHER SUCCESS FOR ANOTHER 5 OR MORE YEARS!

Search Utility

In the course of my job I often need to search for a particular string of text which may appear in any of hundreds of different files beneath a particular directory node. The files may be either gzip conmpressed or non-compressed, and in the case of the gzipped files, there may or may not be a .gz suffix on the filename.

There is no built in facility to do this on a unix system, so I have written a couple of scripts to do the job. The scripts are as follows :-

% cat search
#!/bin/sh
echo "Checking normal files"
find . -name '*' -exec fgrep "$1" {} /dev/null \; 2> /dev/null
echo "Checking compressed files"
find . -name '*' -exec checkit {} "$1" \; 2> /dev/null

And the checkit script which is used by search is as follows :-

#!/bin/sh

gzip -dc $1 | grep $2 > /tmp/asdf1
size=`stat -c %s /tmp/asdf1`
if [ $size -gt 0 ]
then
         echo $1 $2
fi

Then all you need to do is make sure both search and checkit have execute permission and are located in your path. You will need to be logged in as root to issue the commands below.

cp search /usr/bin
cp checkit /usr/bin
chmod 777 /usr/bin/search
chmod 777 /usr/bin/checkit

Alternatively you place the files in a directory underneath your home directory e.g /home/me/bin

Then you need to make sure your environment includes this directory in your path.

export PATH=$PATH:/home/me/bin

Let's see it in action

% search "testing"
Checking normal files
Binary file ./Customer/Products/java/JMSAdapter/lib/weblogic.jar matches
Binary file ./Customer/Products/java/JMS/weblogic.jar matches
./Customer/products/tools/test_iacc.1:testing.
Checking compressed files
./Customer/Products/asdf.gz testing

Very handy indeed.

Programming


QR Code
QR Code search_utility (generated for current page)
 

Advertise with Anonymous Ads