Wednesday, February 20, 2008

Some interesting things you can do with SED:
# more my_wc
#!/bin/sh
sed -n '$=' $1

# more my_head
#!/bin/sh
sed 10q $1

# more my_grep
#!/bin/sh
sed -n '/'$1'/p' $2

#more my_del_lines
#!/bin/sh
sed $1','$2'd' $3

#more my_tac
#!/bin/sh
sed -n '1!G;h;$p' $1

#more my_tail
#!/bin/sh
lines=`wc -l $2 awk '{print $1}' `
start=`expr $lines - $1`
sed "1,$start d" $2

#more line_insert

#!/bin/sh
sed '
/'$1'/ i\
Add this line before every line with WORD
' $2

No comments: