Friday, 13 February 2015

Some useful scripts in my store (will keep updating this post from time to time):

-> print names of all files containing a pattern in current directory:

         for i in `grep -rl "PATTERN" *`;do echo $i; done

-> replace a pattern in all files in current directory:

         for i in `grep -rl "OLD_PATTERN" *`;do sed -i 's/OLD_PATTERN/NEW_PATTERN/' $i; done

-> replace all cpp style comments to c style comments :

            for i in `grep -rl "\/\/" *`;do cp $i $i.bak; sed -i '/\/\//s/.*/& \*\//' $i; sed -i 's/\/\//\/\* /' $i;done