Dec 302013
 

Probably everyone that use a terminal know the command grep, from its man page:

grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By default, grep prints the matching lines.

So this is the best tool to search in big file for a specific pattern, or a specific process in the complete list of running processes, but it has a small limit, it searches for the exact string that you ask, and sometime it could be useful to do an “approximate” or “fuzzy” search.

For this goal the program agrep was firstly developed, from wikipedia we can see some detail of this software:

agrep (approximate grep) is a proprietary approximate string matching program, developed by Udi Manber and Sun Wu between 1988 and 1991, for use with the Unix operating system. It was later ported to OS/2, DOS, and Windows.

It selects the best-suited algorithm for the current query from a variety of the known fastest (built-in) string searching algorithms, including Manber and Wu’s bitap algorithm based on Levenshtein distances.

agrep is also the search engine in the indexer program GLIMPSE. agrep is free for private and non-commercial use only, and belongs to the University of Arizona.

So it’s closed source, but luckily there is an open source source alternative: tre-agrep
Continue reading »

Flattr this!

Nov 252012
 

Terminal
In the past I’ve posted an article regarding the basic usage of grep, one of the commands that I use daily at work to search a text within multiple files, or a text string in the list of running process of a Linux server, but I’ve forgot to show you a small and useful option : How to colour the output that you get from grep to highlight the text you were searching for in a long line.

This is a small option of this powerful command but can save your eyes when searching for a particular property of a Java process that is 4 or 5 lines long.

To be honest I’ve realised this thanks to an article of Alessio, posted recently on his nice blog: http://dark-linux.net and so the following is the translation by me of his article in Italian with some small addition in examples and explanations.

Continue reading »

Flattr this!

Sep 252011
 

Unix based operating systems like Linux offer a unique approach to join two commands on the terminal, with it you can take the output of the first command and use it as input of the second command, this is the concept of pipe or | . Pipes allow two separate process to communicate with each other also if they were not created to do it, so this open an infinite series of opportunity.

A basic example is:

ls -l | grep rwxrwxrwx

This command will print the list of all the files in the local directory that have permission rwxrwxrwx (or that have rwxrwxrwx in their name).

Continue reading »

Flattr this!