Subscribe for email updates

Get all updates to your inbox to stay tune.

Curve tracing programs - Draw sin(x) curve using Graphics programming in C

Learn how to draw curve tracing graphics programs in c language

Graphics programming in C

Learn how to write basic and advanced graphics programming in c language

Curve tracing programs - Draw Cos(x) curve using Graphics programming in C

Learn how to draw curve tracing graphics programs in c language

Make file tutorial

A step by step guide to learn how to write make file in Linux with examples

Thursday, April 26, 2012

Search and replace in Bash scripting

Search and replace is common requirement in any scripting. Bash provides simple way to replace strings/characters in variable.

The bash syntax for search and replace is

${S1//S2/S3}

S1- Source string
S2- String to search
S3 - String to replace with

Lets see simple example.

Example1:  Replace all "/" with "\"

[bash] # var="/home/product/module/lib"
[bash] # var=${var//\//\\} [bash] # echo $var \home\product\module\lib

Example2:  Replace all "product" with "src"

[bash] # var="/home/product/module/lib"
[bash] # var=${var//product/src} [bash] # echo $var /home/src/module/lib [bash] #