sed学习笔记 -n 只打印匹配行

 public@share:~/zhaoyh$ cat input 
# Instruction Guides
1. Linux Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
#  Additional FAQS
6. Windows- Sysadmin, reboot etc.


只打印列匹配列 -n

只打印匹配列的内容

 

public@share:~/zhaoyh$ sed -n '/Linux/p' input 
1. Linux Sysadmin, Linux Scripting etc.
4. Storage in Linux


 只打印匹配列的行号

 

public@share:~/zhaoyh$ sed -n '/Linux/=' input 
2
5


如果没有-n 会怎么样? 

public@share:~/zhaoyh$ sed  '/Linux/p' input 
# Instruction Guides
1. Linux Sysadmin, Linux Scripting etc.
1. Linux Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
#  Additional FAQS
6. Windows- Sysadmin, reboot etc.


public@share:~/zhaoyh$ sed  '/Linux/=' input 
# Instruction Guides
2
1. Linux Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
5
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
#  Additional FAQS
6. Windows- Sysadmin, reboot etc.

结论是打印所有文本内容,并且在匹配行前打印匹配信息

 

 


你可能感兴趣的:(【Bash学习笔记】)