开发者

Sed or Ruby for mundane text processing / dev-productivity tools creation

I want to learn Sed. Can you please point me to good references so that I can fully utilize it.

I want to learn it to perform more of the do-once-then-forget type administrative or dev-tools like tasks. So, I don't really care about performance or modularity or object orientedness etc when writing this type of code. Do you think it would be a good idea to learn Sed? Or should I learn Ruby? My main concern is the conciseness of scripts开发者_运维问答, but not to the point of making it totally obscure looking piece of code.

Thanks Ajay


I can't think of anything that sed is better at than ruby. Sed's syntax for a lot of things is very similar to Ruby sub and gsub string methods. I guess I would point you to Ruby unless you really have no other use for a scripting language other than text processing. You could probably get a reasonable understanding of how to use sed a little quicker than how to do the same stuff in ruby.


  • Sed - an Introduction and Tutorial
  • O'Reilly Sed & Awk book


I would encourage you to take a look at Perl for tasks like this. Many of Perl's features are designed expressly with the goal of "processing text with concise syntax". It can of course jump over into cryptic, but so can Ruby.

Perl also has extensive support for one line programs typed into the shell. echo "hello world" | perl -lpe 's/\b(.)/\U$1/g' prints Hello World


Forget sed, anything more than a simple, line-oriented search and replace is just unreadable. Learn Awk. And then learn Ruby too: it's good for your soul.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜