extracting substring at bash

June 28th, 2007 mysurface

Extracting sub string at Bash is very easy, let say you have a phone number 012-4567890 and you just wanna extract 4567890 out, you can do as below. num=”016-4567890″; echo ${num:5:7} 5 is the starting point and 7 is the string length for sub string. Related Poststar normal operationI am here to show you examples […]

Posted in Bash, Text Manipulation | Hits: 139642 | 15 Comments »

array and for loop in awk

June 25th, 2007 mysurface

grep is always a useful tools to help analyze logs. When the logs are managed nicely in rows and columns format, awk will be much more efficient compared to grep. Refers to simple examples of awk here. Awk support array and for loops. Let say I have IP logs that access to my servers time […]

Posted in awk, Text Manipulation | Hits: 56700 | No Comments »

grep multiple keywords, AND not OR

June 21st, 2007 mysurface

This morning, I asked to analyze log files where I need to grep the lines with two keywords, and the post grep based on multiple keywords doesn’t help much. Refering to the post, where it grep the lines either keyword1 OR keyword2 appears. Where the case I intended to get is different, I need to […]

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

Web Authoring with Vim

June 18th, 2007 toydi

In usual editing, to open a file with vim, we run the command: vim /path/to/file It is also possible to browse a directory using vim: vim /path/to/directory/ When we are inside vim, to save a file, we use the :write command, :read to read an existing file into current buffer; or using :tabnew /path/to/file to […]

Posted in Network, Text Manipulation, vim | Hits: 54476 | 9 Comments »

perform grep and make in vim

June 15th, 2007 mysurface

We can do grep and make in vim, the advantage of doing that in vim compare to terminal is you can use the result to track the error and warning for make or goto the line and files of the grep results. How to make in vim? :make In order to make, the current directory […]

Posted in grep, make, Text Manipulation, vi, vim | Hits: 94735 | 3 Comments »

commenting your source code with combo keys in vim

May 31st, 2007 mysurface

When I saw my colleague commenting his lines of source code with some special combo key in VC++, I would like to do that in vim too. Vim is great that it is highly flexible to extend features with your own define key combos. Vim by default bundle with many default key bindings, fortunately you […]

Posted in Text Manipulation, vi, vim | Hits: 63499 | 5 Comments »

Printing in vim: Using programs other than the default lpr

May 25th, 2007 Felix Leong

Printing in vim is as easy as entering the :hardcopy (or its shorthand equivalent :ha), that command is equivalent to creating a temporary Postscript file and passing it through lpr. But what if you want to modify the printing behaviour of vim? Say, printing 2 pages on a page using the a2ps command?* Luckily that […]

Posted in vim | Hits: 107921 | 8 Comments »

Save typing using vi abbrevations

May 11th, 2007 Felix Leong

Do you find yourself typing some long text too often that it’s getting tiresome (especially when it comes to hard to remember and long email addresses)? Or that you are so bad at remembering today’s date that you have to fumble through the calendar before you are able to type away? If you are using […]

Posted in vi, vim | Hits: 70676 | 2 Comments »

CLI magic: programable bash completion

May 4th, 2007 mysurface

Ubuntu, a Linux distribution that is getting popular because it has successfully improves it’s user friendliness with simple User interface. You can install any applications with few clicks, configuration under GUI dialogs etc. People usually have the thinking of maybe one day, Ubuntu will become another new operating system like Microsoft Windows. Never! The concept […]

Posted in apt-cache, apt-get, Bash, complete, pipeline, sort, svn | Hits: 119058 | 11 Comments »

Sort grep -c results

April 17th, 2007 toydi

grep -c “TODO:” *.c foo.c:1 bar.c:0 spam.c:44 egg.c:32 matrix.c:0 grep -c displays the total count of matching lines for each input file, just like above. Now, to sort the results by total count: grep -c “TODO:” *.c | sort -nt: -k2 bar.c:0 matrix.c:0 foo.c:1 egg.c:32 spam.c:44 It sorts the list by total count or the […]

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