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

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).

主站蜘蛛池模板: 咸丰县| 石景山区| 华容县| 尤溪县| 谢通门县| 五台县| 耒阳市| 平遥县| 金寨县| 资阳市| 措勤县| 哈密市| 柳河县| 滁州市| 太和县| 宜丰县| 楚雄市| 玛纳斯县| 静安区| 瓦房店市| 五指山市| 县级市| 收藏| 平罗县| 白银市| 鹤庆县| 贵德县| 同仁县| 沙洋县| 西丰县| 西青区| 大埔县| 义乌市| 富蕴县| 神农架林区| 开远市| 广饶县| 洛浦县| 台州市| 竹山县| 长寿区|