首页 > 代码库 > sed系列:多命令执行
sed系列:多命令执行
Syntax:
#sed -e ‘command‘ -e ‘command‘ filename
Note: -e option is optional for sed with single command. sed will execute the each set of command while processing input from the pattern buffer.
让我们先创建示例文件
# cat thegeekstuff.txt
1. Linux - Sysadmin, Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Hardware
4. Security (Firewall, Network, Online Security etc)
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
8. Website Design
9. Software Development
$sed -e ‘4d‘ -e ‘2d‘ thegeekstuff.txt
1. Linux - Sysadmin, Scripting etc.
3. Hardware
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
8. Website Design
9. Software Development
$sed -n -e ‘/Storage/p‘ -e /Software/p thegeekstuff.txt
5. Storage
9. Software Development
$sed -e ‘1d‘ -e ‘$d‘ ‘/^$/d‘ thegeekstuff.txt
sed: can‘t read /^$/d: No such file or directory
2. Databases - Oracle, mySQL etc.
3. Hardware
4. Security (Firewall, Network, Online Security etc)
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
8. Website Design
9. Software Development
$sed ‘
> 1d
> $d
> /^$/d
> ‘ thegeekstuff.txt
2. Databases - Oracle, mySQL etc.
3. Hardware
4. Security (Firewall, Network, Online Security etc)
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
8. Website Design
9. Software Development
$
#sed -e ‘command‘ -e ‘command‘ filename
Note: -e option is optional for sed with single command. sed will execute the each set of command while processing input from the pattern buffer.
让我们先创建示例文件
# cat thegeekstuff.txt
1. Linux - Sysadmin, Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Hardware
4. Security (Firewall, Network, Online Security etc)
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
8. Website Design
9. Software Development
10.Windows- Sysadmin, reboot etc
.
例1:删除第1行和第4行$sed -e ‘4d‘ -e ‘2d‘ thegeekstuff.txt
1. Linux - Sysadmin, Scripting etc.
3. Hardware
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
8. Website Design
9. Software Development
10.Windows- Sysadmin, reboot etc.
$sed -n -e ‘/Storage/p‘ -e /Software/p thegeekstuff.txt
5. Storage
9. Software Development
$
$sed -e ‘1d‘ -e ‘$d‘ ‘/^$/d‘ thegeekstuff.txt
sed: can‘t read /^$/d: No such file or directory
2. Databases - Oracle, mySQL etc.
3. Hardware
4. Security (Firewall, Network, Online Security etc)
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
8. Website Design
9. Software Development
$sed ‘
> 1d
> $d
> /^$/d
> ‘ thegeekstuff.txt
2. Databases - Oracle, mySQL etc.
3. Hardware
4. Security (Firewall, Network, Online Security etc)
5. Storage
6. Cool gadgets and websites
7. Productivity (Too many technologies to explore, not much time available)
8. Website Design
9. Software Development
$
sed系列:多命令执行
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。