Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

« Newer Snippets
Older Snippets »
3 total  XML / RSS feed 

How to count particular words using perl

When "grep -c" doesn't cut it (counts only 1 occurrence per line).

perl -lne '$c++ while /SEARCH_STRING/g; END { print $c; }'


For example, to count the number of times ABCD appears in mysqldump output:

mysqldump my_db | perl -lne '$c++ while /ABCD/g; END { print $c; }'


Modified version of snippet found in http://www.wellho.net/forum/Perl-Programming/Issue-with-Grep.html

How to count particular words in vim

From one of the comments in http://www.vim.org/tips/tip.php?tip_id=689

:%s/word/&/g


The above substitutes "word" for itself, and tells you the number of substitutions made.

tar and gzip on one line

Bundle my_dir
tar cvf - my_dir | gzip -c > my_dir.tar.gz


Unbundle my_dir
gunzip -c my_dir.tar.gz | tar xvf -
« Newer Snippets
Older Snippets »
3 total  XML / RSS feed