sed command review

Command

What It Does

sed –n '/sentimental/p' filex

Prints to the screen all lines containing sentimental.

The file filex does not change. Without the –n option, all lines with sentimental will be printed twice.

sed '1,3d' filex > newfilex

Deletes lines 1, 2, and 3 from filex and saves changes in newfilex.

sed '/[Dd]aniel/d' filex

Deletes lines containing Daniel or daniel.

sed –n '15,20p' filex

Prints only lines 15 through 20.

sed '1,10s/Montana/MT/g' filex

Substitutes Montana with MT globally in lines 1 through 10.

sed '/March/!d' filex (csh)
sed '/March/!d' filex (sh)

Deletes all lines not containing March. (The backslash is used only in the csh to escape the history character.)

sed '/report/s/5/8/' filex

Changes the first occurrence of 5 to 8 on all lines containing report.

sed 's/....//' filex

Deletes the first four characters of each line.

sed 's/...$//' filex

Deletes the last three characters of each line.

sed '/east/,/west/s/North/South/' filex

For any lines falling in the range from east to west, substitutes North with South.

sed –n '/Time off/w timefile' filex

Writes all lines containing Time off to the file timefile.

sed 's/([Oo]ccur)ence/1rence/' file

Substitutes either Occurence or occurence with Occurrence or occurrence.

sed –n 'l' filex

Prints all lines showing nonprinting characters as nn, where nn is the octal value of the character, and showing tabs as >.

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8730/viewspace-1034434/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/8730/viewspace-1034434/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值