What are the differences between Perl, Python, AWK, and sed? Is it better to handle text using that scripting language? What is the reason?

Source: Internet
Author: User
If there are other scripting languages, please also list

Reply content:

    • Sed-when you need to does simple text transforms on files.
    • Awk-when need simple formatting and summarization or transformation of data.
    • Perl-for almost any task, but especially when the task needs complex regular expressions.
    • Python-for the same tasks that's could use of Perl for.

Here's a full answer: / http stackoverflow.com/quest ions/366980/what-are-the-differences-between-perl-python-awk-and-sed Awk's ability to work on text processing is strong, and for the sake of convenience it is possible that you will use it with SED because it is easy to use the regular, and the regular aspect of awk is weak, for example, when working with text, you might first use SED for initial processing, Then using awk will reduce the complexity of logic. Python can also handle text, but if the logic is not particularly complex, it is recommended to use awk, because the same complexity of logic, Python code is usually very large. The use of awk is interesting, many tasks can be handled with awk, such as tonight, I got a caption found in both Chinese and English subtitles, occupy the screen is very large, and then a sentence can be removed English subtitles:
Gawk.exe "$!~/^[a-za-z]/{print $}" 1.SRT > 2.srt

:) Perl, Ruby, Python, descending by recommended index, and also learning difficulty descending. Simple handling with Sed/awk. Working with text do not use regex, awk these one-liner language, honestly use your most familiar universal language, multi-step processing, with multiple intermediate variables and multi-line processing the best, so easy to understand and easy to debug

Those one-liner, apart from looking "compact," are really useless.
If not mastered any one, then all try, which handy, and someone around you can consult, that is the best.

Which language can do a lot of things.
Python can do anything.
Awk is primarily about statistics and reporting.
Sed mainly lies in the regular, but looks dizzy. Perl is the first choice of text processing, want to replace the awk sed is easy, want to write a high-readability program is also easy to see how you use, some beginners blindly using Perl to cause 4, Perl is a more efficient development of the language, Python is not as good as Java With groovysed own use of not much, mainly used in bulk replacement inside
This place has a little trick, sed don't use default/do delimiter, too troublesome, usually I use the # number, also can use other characters, such as @ and other characters
Sed-n "S#A#B#GP" verification is not right,
Sed-i "s#a#b#g" Change file

Obvious breakdown of input data, filtering, changing the format of the output, such as a single print field, with awk handy

Generally more complex statistics, such as those involving multiple lines of statistics, are used in Python, also 3, 4 lines

The legend is that Perl is powerful and useless ... The main thing is that they are not good, always feel a string of regular like the heavenly Book
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.