Global Regular Expression Print Tools (grep variants)

February 25th, 2008

The UNIX grep utility marked the birth of a global regular expression print (GREP) tools. Searching for patterns in text is important operation in a number of domains, including program comprehension and software maintenance, structured text databases, indexing file systems, and searching natural language texts. Such a wide range of uses inspired the development of variations of the original UNIX grep. These variations range from adding new features, to employing faster algorithms, to changing the behaviour of pattern matching and printing.
Read the rest of this entry »

how do i grep on a term with a $ in it such as $foo? i tried enclosing it in quotes but that doesn’t help

February 16th, 2009

Enclose the $ in square brackets [ .. ], that is, specify the special character as a character class. For example,

grep ‘[$]foo’ file.txt

Negation in regular expressions

February 14th, 2009

How to search for lines that don’t contain a particular pattern is fairly easy in some programs, obscure in others, and almost impossible yet in others. That is, assuming your program of choice supports regular expressions. I review how to achieve this functionality in Perl, Vim, grep, and vi.
Read the rest of this entry »

if I wanted to match ‘foo13245’, can I use grep ‘foo[\d]*’?

January 7th, 2009

Nope, \d has no meaning (unless using -P for PCRE). You need [[:digit:]] instead; i.e.,

grep 'foo[[:digit:]]*'

How can i search for files which contain string A but not string B ?

January 6th, 2009

Pipe the output of grep through grep -v. For example:

grep 'A' file | grep -v 'B'

Why grep ‘foo|bar’ file doesn’t work?

January 5th, 2009

The bar | has no special meaning in BRE (basic regular expressions). Use extended regular expressions (ERE) such as:

grep -E 'foo|bar' file


egrep 'foo|bar' file

In GNU grep, you can also force the spcial meaning of | by escaping it. E.g.,

grep 'foo\|bar' file

Is grep an acronym? Does it mean GNU Regular Expression P?

January 4th, 2009

grep originated from ed command: g/re/p where re is a regular expression, g stands for globally, and p stands for print. So one could say grep is an acronym of “Global Regular Expression Print“.

HTTP Proxy Over SSH Connection Mini-Howto

July 9th, 2008

What is HTTP Proxy?

HTTP proxy is a method to connect to a website by through an intermediate “proxy” server. The way it works is that your browser sends the request for a web page to the proxy server. The proxy server then forwards the request to the website. The website sends the requested page back to the proxy server, which in turn sends it back to your browser.

Uses of HTTP Proxy

HTTP proxy is most commonly used in two cases: (1) you want to fake your identity to the website; and (2) you want to bypass a firewall.
Read the rest of this entry »

Book Review: “Stealing the Network: How to Own a Continent”

February 26th, 2008

“Stealing the Network: How to Own a Continent” is an interesting technical hacker story. Even though the plot of the story is not very well connected, the authors develop the story using real technology to compromise computer networks, which makes you feel that this is not just a fiction and it might be actually happening somewhere in the world right now.

The book shows the intuition of people who became hackers. It also shows how the hackers’ business works and how they communicate. Many various kinds of hacking techniques and tools are mentioned ranging from social engineering, several kid hacking tool, and good (or I should say bad) uses of available legitimate resources. The authors show how hackers collaborate and make use of different types of networks and security holes to help them accomplish their goal.
Read the rest of this entry »

Book Review: “Essential System Administration”

February 23rd, 2008

All you need to know about managing Linux/UNIX/BSD.
At first glance, this book seems like a typical O’Reilly book: a narrow title, rich in material, and is beneficial to a much wider audience than the title reveals. It covers a wide range of system administration subjects and goes way beyond just the essentials.

Over the years, I have administered several multi-user UNIX, Linux, and FreeBSD servers. I believed that I knew the essentials, because if I did not, I would not have been able to do my job all these years. I wanted to see if the things that I learned by experience, often the hard way, are included in “Essential System Administration”. Sure enough, they were all there. Not only that, but they were laid out simply, without much unnecessary technical details, and accompanied by numerous examples and anecdotal encounters by the author. If you read one section, you would be able to apply the knowledge and skills that it describes right away. For instance, you don’t need to read the entire manual of procmail in order to write some effective mail filters; chapter 9 has a section on “Mail Filtering with procmail” that covers the essentials.
Read the rest of this entry »