官术网_书友最值得收藏!

  • Bash Cookbook
  • Ron Brash Ganesh Naik
  • 242字
  • 2021-07-23 19:17:36

Using SED and AWK to remove/replace substrings

Again, when we need to remove a pesky character or remove sections of strings upon occurrence, we can always rely on these two powerful commands: sed and awk. And while we saw that Bash does indeed have a similar functionality built-in, the full tools are able to offer the same and more complex functionality. So, when should we use these tools?

  • When we care less about the speed that might be gained by using the built-in functionality of Bash
  • When more complex features are needed (when programming constructs like multi-dimensional arrays are required or editing streams)
  • When we are focused on portability (Bash might be embedded or a limited version and standalone tools may be required)
Complete books have been written on both SED and AWK, and you can always find far more information online at  https://www.gnu.org/software/sed/ and  https://www.gnu.org/software/gawk/.

Stream editor (SED) is a handy text manipulation tool that is great for one-liners and offers a simple programming language and regex matching. Alternatively, AWK is also powerful and arguably more than SED. It offers a more complete programming language with a variety of data structures and other constructs. However, it is better suited when working with files such as CSVs, which may contain fields or structured data, but SED can be better when working with text substitutions when working with pipes (for example, grep X | sed ... > file.txt).

主站蜘蛛池模板: 尤溪县| 漯河市| 平山县| 长丰县| 临澧县| 琼结县| 德化县| 乌苏市| 宝山区| 屯留县| 体育| 健康| 盐池县| 沁水县| 南江县| 财经| 隆林| 永靖县| 华亭县| 宝鸡市| 兴义市| 北海市| 金湖县| 东乡| 丹寨县| 十堰市| 高清| 阳江市| 勃利县| 利川市| 四平市| 金平| 合山市| 哈尔滨市| 达尔| 开封县| 左权县| 鹤山市| 响水县| 临沭县| 施秉县|