网站性能优化,网站在线演示,竞价网,用游戏人物做网站属于侵权吗sed命令是我们在linu类系统中非常重要的一个命令, 但是在macos下面默认是没有sed命令的, 不过我们可以通过brew install gnu-sed ( 或者通过 sudo port install gsed )这个软件包来获得这个命令
GNU sed 命令安装
下面2种方式,选择一种安装即可
# brew安装
brew install gn…sed命令是我们在linu类系统中非常重要的一个命令, 但是在macos下面默认是没有sed命令的, 不过我们可以通过brew install gnu-sed ( 或者通过 sudo port install gsed )这个软件包来获得这个命令
GNU sed 命令安装
下面2种方式,选择一种安装即可
# brew安装
brew install gnu-sed# macport 安装
sudo port install gsed
macos里面在brew install gnu-sed安装后的默认命令是 gsed, 如果我们希望使用sed命令需要在配置文件 ~/.bash_profile 里面增加命令别名: alias sedgsed 或者在 ~/.bash_profile 中增加sed命令的路径到path export PATH/usr/local/opt/gnu-sed/libexec/gnubin:$PATH GNU sed 命令使用示例
sed流编辑器是一个非交互式命令行文本编辑器。
# 示例删除文件中的第4行
$ sed 4d input.txt output.txt#示例将第10-20行中每次出现的“hello”替换为“world”
$ sed 10,20s/hello/world/ input.txt output.txt
sed通常用于过滤文本即它接受文本输入对其执行一些操作或一组操作并输出修改后的文本。sed通常用于使用模式匹配或替换文件中字符串的多次出现来提取文件的一部分。 参考 gnu sed官方使用手册 sed, a stream editor 1 Introduction2 Running sed 2.1 Overview2.2 Command-Line Options2.3 Exit status3 sed scripts 3.1 sed script overview3.2 sed commands summary3.3 The s Command3.4 Often-Used Commands3.5 Less Frequently-Used Commands3.6 Commands for sed gurus3.7 Commands Specific to GNU sed3.8 Multiple commands syntax 3.8.1 Commands Requiring a newline4 Addresses: selecting lines 4.1 Addresses overview4.2 Selecting lines by numbers4.3 selecting lines by text matching4.4 Range Addresses5 Regular Expressions: selecting text 5.1 Overview of regular expression in sed5.2 Basic (BRE) and extended (ERE) regular expression5.3 Overview of basic regular expression syntax5.4 Overview of extended regular expression syntax5.5 Character Classes and Bracket Expressions5.6 regular expression extensions5.7 Back-references and Subexpressions5.8 Escape Sequences - specifying special characters 5.8.1 Escaping Precedence5.9 Multibyte characters and Locale Considerations 5.9.1 Invalid multibyte characters5.9.2 Upper/Lower case conversion5.9.3 Multibyte regexp character classes6 Advanced sed: cycles and buffers 6.1 How sed Works6.2 Hold and Pattern Buffers6.3 Multiline techniques - using D,G,H,N,P to process multiple lines6.4 Branching and Flow Control 6.4.1 Branching and Cycles6.4.2 Branching example: joining lines7 Some Sample Scripts 7.1 Joining lines7.2 Centering Lines7.3 Increment a Number7.4 Rename Files to Lower Case7.5 Print bash Environment7.6 Reverse Characters of Lines7.7 Text search across multiple lines7.8 Line length adjustment7.9 Reverse Lines of Files7.10 Numbering Lines7.11 Numbering Non-blank Lines7.12 Counting Characters7.13 Counting Words7.14 Counting Lines7.15 Printing the First Lines7.16 Printing the Last Lines7.17 Make Duplicate Lines Unique7.18 Print Duplicated Lines of Input7.19 Remove All Duplicated Lines7.20 Squeezing Blank Lines8 GNU sed’s Limitations and Non-limitations9 Other Resources for Learning About sed10 Reporting BugsAppendix A GNU Free Documentation LicenseConcept IndexCommand and Option Index