Some GNU sed examples

sed

According to wikipedia, sed is a Unix utility that parses and transforms text, using a simple, compact programming language.

Examples

Modify an element inside files


For example, we modify each 011.html term by xperia_bouygues.html :

user@host:~$ sed -i 's/011.html/xperia_bouygues.html/' *.html

Print file without comments

user@host:~$ cat myfile | sed '/^#/d'

Print file without blanks lines

user@host:~$ cat myfile | sed '/^$/d'

Keep only lines with matching term

user@host:~$ sed -n -i '/vmail/p' /etc/courier/authlib/userdb/system

Delete carriage returns

user@host:~$ cat file | sed ':a;N;$!ba;s/\n//g'

Delete empty lines repetition

user@host:~$ cat file | sed 'N;s/^\n$//;P;D'

Uppercase first letter of files names

user@host $ for i in *mp3; do I=$(echo "$i" | sed -e "s/\b\(.\)\([a-z]* \)/\u\1\2/g"); mv "$i" "$I"; done
Licence Creative Commons
This website http://shebangthedolphins.net is licensed to the public under a licence Creative Commons Attribution licence.
Contact :