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: 195637 | 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: 368852 | 49 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: 129421 | 11 Comments »

Enable a user to gain write permission when mounting

October 10th, 2006 mysurface

We need to perform mounting with root privilege, but after a simple mounting, we need to be root in order to write to the mounting point. This is the default for a simple mounting, check out more mounting examples here. But we can grant the mount point ownership to other user besides root. We can […]

Posted in Admin, cat, mount, pipeline | Hits: 82786 | 2 Comments »

easily extract a column of data from multiple columns

October 2nd, 2006 mysurface

To extract a column of data from multiple column, we can use cut. Usually cut use to extract value from huge trace file or data file such as /etc/passwd. To extract all available user name from /etc/passwd, you can do this cut -d”:” -f1 /etc/passwd Cut extract value line by line, to put all into […]

Posted in cut, Misc, pipeline, Text Manipulation, xargs | Hits: 115835 | 5 Comments »

xargs use stardard output as parameter for another command

October 2nd, 2006 mysurface

xargs is a command line of findutils package. It is not so common for new user, but it is a very useful tools, let me pick an example to show the usage. Bare in mind, xargs is a kind of combo command use together with other command through pipeline. I have a list of links […]

Posted in cat, pipeline, Text Manipulation, wget, xargs | Hits: 84375 | 10 Comments »

Redirect stderr to stdout

October 1st, 2006 toydi

Very simple, just remember: 1 = stdout 2 = stderr In python, its unittest module loves to dump test results to stderr (rather than stdout). In order to pipe the results to less , you may need to redirect stderr to stdout: python 2>&1 | less To redirect stderr into a file: python […]

Posted in pipeline, stderr, stdout | Hits: 144650 | 7 Comments »

generate and print a sequence of number

September 28th, 2006 mysurface

To generate a sequence of number we can use seq seq 1 10 With this it prints 1 to 10 line by line, because by default separator is new line, anyway you can check, do this seq -s” ” 1 10 Doing this it change new line to a single blank space. But that is […]

Posted in backquote, cat, Misc, pipeline, seq, Text Manipulation, wc | Hits: 102517 | 1 Comment »

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: 66698 | 5 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: 46118 | 1 Comment »