Loading...

Tagged: grep RSS

  • The SourceBench 8:14 pm on December 20, 2009 Permalink | Reply
    Tags: ack, Bash/shell, grep   Posted in Blog posts

    Ack is better than grep! – And it’s not only their slogan. 

    I recently was pointed to ack for scanning a huge pile of files for a certain pattern. So far I was always using grep, awk, cut, sed and such in combination with find to build whatever I needed. But having a look at ack reveals that my life could have been much easier. Here are some simple examples:

    Search for a pattern recursively through directories, while ignoring .svn, CVS and other VCS directories:
    With grep: grep pattern $(find . -type f | grep -v '\.svn')
    With ack: ack pattern

    Search for a pattern in all perl files, while ignoring .svn directories:
    With grep: grep pattern $(find . -name '*.pl' -or -name '*.pm' -or -name '*.pod' | grep -v .svn)
    With ack: ack --perl pattern

    That’s it for the basics. More on their manual page at http://betterthangrep.com/

    Just a last one:
    Get a list of all functions and their parameters attached to your “wp_head” action hook of a WordPress installation.
    With grep: please don’t make me do it.
    With ack: ack "add_action\((.*[\"|'](.*)[\"|'][,|\s]+.*)\)" --output="hook: \$1, params: \$2"

     
  • The SourceBench 11:05 pm on December 4, 2009 Permalink | Reply
    Tags: , grep, list, sed,   Posted in Bash/shell

    Get a list of urls/domains from a text file 

    sed 's/http/\^http/g' FILENAME | tr -s "^" "\n" | grep http| sed 's/[\ |\\\|\"].*//g' | sed "s/['].*//g" | sort | uniq

     
  • The SourceBench 1:40 pm on November 27, 2009 Permalink | Reply
    Tags: find, function, grep, linux, PHP, search   Posted in Bash/shell

    Search for a function definition in a bunch of php files 

    find . -name *.php -exec grep -HE "function FUNCTION_NAME" {} \;

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel