0%

sed 入门

sed command examples

When you copy a DOS file to Unix, you could find \r\n in the end of each line. This example converts the DOS file format to Unix file format using sed command.

1
$sed 's/.$//' filename

Print file content in reverse order

1
$ sed -n '1!G;h;$p' thegeekstuff.txt

Add line number for all non-empty-lines in a file

1
$ sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /'

More sed examples: Advanced Sed Substitution Examples

处无为之事,行不言之教;作而弗始,生而弗有,为而弗恃,功成不居!

欢迎关注我的其它发布渠道