“Number” Manipulation in Grep

November 7th, 2006 liewsheng

“grep” will able to display the lines match with keyword or non-keyword (using option “-v”), but you may want to continue to display another few lines after/before the matched keyword: grep -A N “keyword” filename this will continue display N lines after the matching line. To display the N lines before matching line : grep […]

Posted in grep, Text Manipulation | Hits: 30644 | 8 Comments »

Exclusive Grep

November 7th, 2006 liewsheng

When you have ‘grep’ some keyword: grep “keyword” filename tons of lines and dozen of words you don’t want may show on the screen. What can you for this? Of cause is filter out the unwanted word ;p it is easy to ‘exclusive’ the unwanted keyword: grep “keyword” filename | grep -v “non-keyword” the ‘-v’ […]

Posted in grep, Text Manipulation | Hits: 47509 | 21 Comments »

Regular expression with egrep and ls

October 7th, 2006 mysurface

egrep is actually same as grep -E, it interpret PATTERN as an extended regular expression. Therefore ESCAPE ( \ ) is not needed for certain symbol. ls is a common tool for listing file that matches the keyword. Regular expression (RE) is a very important and useful to manipulating strings and text. In this example, […]

Posted in egrep, grep, ls, Regular Expression, Symbol, Text Manipulation | Hits: 96089 | 4 Comments »

grep with color

October 5th, 2006 mysurface

Nowadays most of the time, terminal support coloring. For example when you list the files in a directory, the file listed with display with different color, which indicate different type of files. Grep too, support color, you can do this grep –color “printf” src grep will list all lines from files in src directory which […]

Posted in grep, Misc, Text Manipulation | Hits: 16412 | 6 Comments »

grep based on multiple keywords

September 28th, 2006 mysurface

grep with multiple keywords need some knowledge of regular expression. But that is not difficult, use (OR). Let say you want to grep “me” and “you” at world.txt, you do grep “me\|you” world.txt You need to put ESCAPE STRING ( \ ) for OR ( | ), else it will treat it as a simbol […]

Posted in egrep, grep, Text Manipulation | Hits: 66259 | 7 Comments »

query using debian packaging manager

September 24th, 2006 mysurface

I am here to show you two examples of using dpkg to query package info. To know what deb package is installed, you can do this dpkg -l Usually we do this with grep, to filter only info that we are interested in, let say i want to know the packages consist of keyword gcc. […]

Posted in Admin, backquote, dpkg, grep, pipeline, which | Hits: 58190 | 5 Comments »

searching files with locate, find and grep

September 18th, 2006 mysurface

I am here to show you 3 ways to search for files in linux. locate is the most easilest way to search for files. To search for a file with filename hello.c locate hello.c You need to update the database in order to search for files completely, like this updatedb For security purpose, sometimes, it […]

Posted in Common, find, grep, locate, Text Manipulation | Hits: 50538 | 2 Comments »

invert match with grep

September 16th, 2006 mysurface

Usually if you want to search for string with specific keyword, you use grep. cat /etc/passwd | grep root This will list all lines with keyword “root” . What if you want to list all entry without keyword “root” ? cat /etc/passwd | grep -v root Related Postsgrep multiple keywords, AND not ORThis morning, I […]

Posted in grep, Text Manipulation | Hits: 21563 | 2 Comments »

grep for a few lines

September 15th, 2006 mysurface

One of the useful option for grep, when you find the keyword you are searching, instead of return a particular line that contains the keyword, it allows you to specified how many lines to return by specified -A option. Let say I want to return 5 lines when i found “main” at hello.c. grep -A […]

Posted in grep, Text Manipulation | Hits: 15981 | 3 Comments »

get to know which command use to trigger the GUI program

September 9th, 2006 mysurface

If you are light weight windows manager user which depend on certain desktop such as kde, gnome, sometimes you want to know what is the command that call a particular program that you usually click with your mouse in kde/gnome, so that you can run it in console or trigger with key mapping. You can […]

Posted in grep, pipeline, X11, xprop | Hits: 41233 | 1 Comment »