sed命令笔记

直接修改文件:-i

1. 修改所有行:

sed ‘s/oldstring/newstring/g’ [filename]

2.修改第4~10行:

sed ‘4,10s/oldstring/newstring/g’ [filename]

3.删除:

sed ‘1,3d’ [filename] (删除1到3行)

sed ‘$d’ [filename] (删除尾行)

sed ‘/^th/d’ [filename] (删除开头为th的行)

sed ‘/^$/d’ [filename] (删除空行)

4.多次编辑:

sed -e [action1] -e [action2] -e [action3] … [filename]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s