Wednesday, August 15, 2007

sed - basic uses

Sed is very useful.

First sample, the most basic use, find a string and replace it.
I can used to to access my bash script.

#!/bin/sed -f

# at the end of the file
# add comments
$ {
# author mark.chen \
# date 2007 \
# end

and my script

#! /bin/bash

export MIDIFILE=/root/Desktop/nelly.mid
export PLAYER=/usr/local/RealPlayer


Second, "dos2unix.sed". It may not perfect, I am still learning sed, but I used it remove "^M" or 0x0d from code. The use is "dos2unix.sed a.c > a_2.c", if the output is the same as the input, it may not work, so make sure the output is different

#! /bin/sed -f