Split screen console terminal ~ Terminator

January 3rd, 2010 mysurface

Sometimes, you may have many logs to trace at once, you may need to copy and paste text from files to files, and tabbed terminal is just not convenient enough. So, you hope for a terminal that allows you to split your console screen into either horizontal or vertical flexibly. If you have such requirements […]

Posted in Misc, terminator | Hits: 222125 | 2 Comments »

Bash script that process input from pipeline or file redirection

November 15th, 2008 mysurface

I remember I wrote a post regarding how to makes python processing string from the pipeline stream. This time, I find the needs to do it in bash script. I created a hex string splitter script for my friend who needs to decode the raw data that will be written in hex string such as […]

Posted in Bash, pipeline | Hits: 189007 | 8 Comments »

How to redirect output to a file as well as display it out

December 6th, 2007 mysurface

To redirect standard output to a file is easy, you just need to use the redirection symbol, for example: echo “hello world” > test.txt But what if I want to display it out as well as store into a file? Answer: tee echo “hello world” | tee test.txt Okay it seems very easy, how about […]

Posted in pipeline, python, tee, Text Manipulation | Hits: 354201 | 47 Comments »

pcregrep, grep based on perl compatible regular expressions

November 20th, 2007 mysurface

grep supposedly support perl regex by specified -P option, but somehow my grep do not support that, it complains this when I trigger with -P grep: The -P option is not supported But when you check the manpage of grep, you will see this -P, –perl-regexp Interpret PATTERN as a Perl regular expression. I found […]

Posted in pcregrep, printf, Regular Expression, Text Manipulation | Hits: 151520 | 3 Comments »

smart grouping shorten long command line 2

June 19th, 2007 mysurface

This post is to illustrate additional usage of curly brackets { } for range of numbers, continues from smart grouping shorten long command line. Let say you have a list of logs where you want to pick a range of logs for analysis, the sample log files shows as bellow tcp_06062007_1.txt … tcp_06062007_180.txt tcp_06062007_181.txt tcp_06062007_182.txt […]

Posted in curly brackets, Symbol, tar | Hits: 61481 | 1 Comment »

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: 119324 | 11 Comments »

Redirect output to multiple processes

November 8th, 2006 toydi

Since tee can read the standard input, and write to multiple files, we may leverage this feature so that it writes to multiple processes (instead of files). tee >(process1) >(process2) >(process3) | process4 >( ) (see process substitution) pretends itself as a write-only file. Everything you write into it, will be passed to the command […]

Posted in Common, grep, process substitution, tee | Hits: 184432 | 61 Comments »

Compare two directory listings

November 8th, 2006 toydi

Given two directories: ~/dir-new/ and ~/dir/, $ ls ~/dir-new/ file-01.txt file-02.txt file-new.txt $ ls ~/dir/ file-01.txt file-02.txt file-old.txt To compare them: comm

Posted in comm, process substitution, Text Manipulation | Hits: 115653 | 16 Comments »

Rename multiple files

November 5th, 2006 toydi

Often over time, we will want to reorganize a group of files by renaming them. To rename *.txt to *.bak (e.g. to rename ham.txt to ham.bak) for f in *.txt; do mv “$f” “${f%.txt}.bak”; done To remove ‘new-‘ from new-* (e.g. to rename new-ham.txt to ham.txt) for f in new-*; do mv “$f” “${f#new-}”; done […]

Posted in Common, for, mv, Regular Expression | Hits: 208564 | 29 Comments »

square brackets in regular expression

October 17th, 2006 mysurface

Previously we have an example on regular expression, but It doesn’t shows the power of square brackets ( [ ] ) Let say you want to search for string fprintf, vprintf and sprintf using grep, usually what you do is egrep “fprintf|vprintf|sprintf” *.c You may be ask why don’t just uses the word “printf”? If […]

Posted in egrep, Regular Expression, Text Manipulation | Hits: 89884 | 7 Comments »