[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] gawk和sed各自的特点是什么

gawk 和 sed 各自的特点是什么,或者说各自的优缺点是什么。
用批处理处理文本的时候最多,但bat处理文本太弱,所以一直想学sed gawk
因理解能力和精力有限打算先从一样入手,不知该选择哪样.
sed 太晦涩,感觉gawk要容易入门点,但不知道二者功能上有什么区别,望老手们指点指点。

另外再问句,sed 或 gawk 对行的长度有限制吗?会不会有溢出的情况发生?
技术问题请到论坛发帖求助!

本帖最后由 Demon 于 2011-6-2 19:29 编辑

处理文本传说是Perl比较牛逼,菜鸟路过。

TOP

1) What is the difference between awk and sed ?

Both are tools that transform text. BUT awk can do more things besides just manipulating text. Its a programming language by itself with most of the things you learn in programming, like arrays, loops, if/else flow control etc You can "program" in sed as well, but you won't want to maintain the code written in it.

2) What kind of application are best use cases for sed and awk tools ?

Conclusion: Use sed for very simple text parsing. Anything beyond that, awk is better. In fact, you can ditch sed altogether and just use awk. Since their functions overlap and awk can do more, just use awk. You will reduce your learning curve as well.

大概意思是说awk功能更加丰富一些,它的数组、循环、流程控制等显得容易些。

sed is a stream editor. It works with streams of characters on a per-line basis. It has a primitive programming language that includes goto-style loops and simple conditionals (in addition to pattern matching and address matching). There are essentially only two "variables": pattern space and hold space. Readability of scripts can be difficult. Mathematical operations are extraordinarily awkward at best.

awk is oriented toward delimited fields on a per-line basis. It has much more robust programming constructs including if/else, while, do/while and for (C-style and array iteration). There is complete support for variables and single-dimension associative arrays plus (IMO) kludgey multi-dimension arrays. Mathematical operations resemble those in C. It has printf and functions. The "K" in "AWK" stands for "Kernighan" as in "Kernighan and Ritchie" of the book "C Programming Language" fame (not to forget Aho and Weinberger). One could conceivably write a detector of academic plagiarism using awk.

大概意思是说sed侧重于行处理,awk侧重于列处理。
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

我也是很想知道,学习学习

TOP

返回列表