pass variable to awk from outside

October 17th, 2006 mysurface

Many people uses awk in their shell script, but they need to pass variable to awk for manipulation, it is not difficult, bellow is a simple example. awk ‘END { print myval }’ myval=`pwd` data.txt This example is to show you, I successfully pass a value from outside, at the END of the manipulation, print [...]

Posted in awk, Bash, Text Manipulation | Hits: 29161 | 2 Comments »

if … then … fi

October 13th, 2006 mysurface

if iis a basic programming checking for condition and reacts based on the condition, bash uses if to check for File integer String For checking the File, let say your file name is stored at $fn, and you wanna check the file is exist ? do this: if [ -e $fn ] then echo “$fn [...]

Posted in Bash, echo, if, Misc | Hits: 89110 | 7 Comments »

writting executable script

October 8th, 2006 mysurface

Shell script (sh), Bash script (bash), Python and perl are all scripting language. By default, to run a scripting file, for example Python script, you need to do this: python myscript.py Another example for shell script: sh myscript.sh But we make is executable and can execute by running directly like this ./myscript.py If you place [...]

Posted in Bash, chmod, Developer, file, python, sh, which | Hits: 76865 | 9 Comments »

Run multiple commands consequently

October 3rd, 2006 mysurface

By specified terminator ( ; ) like in C/C++ programming, you can run multiple commands consequently. We usually want to do this when we want to compile and install source code for certain packages. ./configure;make;make install Bash first execute the configure, then make , consequently will install the package. But bare in mind, bash have [...]

Posted in du, read, Symbol, terminator, while | Hits: 82824 | 5 Comments »