sed is a great magic tool in stream editing, I use this to cope with cookie file generated by curl

sed '/^ *#.*/d' cookie  #delete commented lines
sed '/^$/d' cookie      #delete blank lines
sed '/^\s.*$/d' cookie  #delete lines that is blank or just looks bland
sed 's/rugal/bernstein/g' file  #replace all matched rugal with bernstein globally

The command above will only print modified string to STDOUT.

You could edit string in-place by specifying -i option.

sed -i 's/rugal/bernstein/g' file  
# replace matched string with bernstein and edit them in file

To pass bash variables into sed, you need to use double quote to replace single quote:

# replace match what $1 represent and append with ;$2
sed "s/$1/$1;$2/g" data

Use \1 to represent the matched pattern.

#Append a space right after header tag in markdown syntax
sed 's/^\(#\+\)/\1 /'   text


Published

10 December 2013

Category

operation

Tags