Unix Sed

sed '5d' Delete line 5

sed '/[Tt]est/d' Delete all lines containing Test or test

sed -n '20,25p' text Print only lines 20 through 25 from text

sed '1,10s/unix/UNIX/g' intro Change unix to UNIX wherever it appears in the first 10 lines of intro

sed '/jan/s/-1/-5/' Change the first -1 to -5 on all lines containing jan

sed 's/...//' data Delete the first three characters from each line of data

sed 's/...$//' data Delete the last 3 characters from each line of data

sed -n 'l' text Print all lines from text, showing nonprinting characters as /nn (where nn is the octal value of the character), and tab characters as /t


$ cat intro
The Unix operating system was pioneered by Ken
Thompson and Dennis Ritchie at Bell Laboratories
in the late 1960s. One of the primary goals in
the design of the Unix system was to create an
environment that promoted efficient program
development.

$

$ sed 's/Unix/UNIX/' intro Substitute Unix with UNIX

The UNIX operating system was pioneered by Ken
Thompson and Dennis Ritchie at Bell Laboratories
in the late 1960s. One of the primary goals in
the design of the UNIX system was to create an
environment that promoted efficient program
development.
$

$ sed -n '1,2p' intro Just print the first 2 lines

The UNIX operating system was pioneered by Ken
Thompson and Dennis Ritchie at Bell Laboratories

$

$ sed -n '/UNIX/p' intro Just print lines containing UNIX

The UNIX operating system was pioneered by Ken
the design of the UNIX system was to create an

$

$ sed '1,2d' intro Delete lines 1 and 2

in the late 1960s. One of the primary goals in
the design of the UNIX system was to create an
environment that promoted efficient program
development.

$

$ sed '/UNIX/d' intro Delete all lines containing UNIX

Thompson and Dennis Ritchie at Bell Laboratories
in the late 1960s. One of the primary goals in
environment that promoted efficient program
development.

$
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值