Linked by pkrumins on Thu 19th Feb 2009 12:17 UTC
General Development If you have ever been interested in awk and sed Unix utilities, then you probably know about the awk1line.txt and sed1line.txt files that are floating around the Internet. Each file contains around 80 idiomatic sed and awk one-liners for performing various text modification tasks.
Thread beginning with comment 349936
To view parent comment, click here.
To read all comments associated with this story, please click here.
Michael
Member since:
2005-07-01

Regular expressions are very powerful but they cover a limited range of problems between the the trivial (the title is the example given to trim whitespace) and the very complex.

These old UNIX tools were terific in their day when they were the only way of doing things. But I think the fact that they continue to get so much air time has more to do with the fact that it's fun play with them. They're like crossword clues.

Don't underestimate what you can do with Python. It's trivial to read in a text file and split it into an array using whatever seperator you want. Modern scripting languages have tremendously powerful string handling functions and they do all this using real words. RE's are there if you need them but you very rarely do.

My work rate isn't limited by the speed at which I type, it's limited by the speed at which I think (that is, severely limited). I think better if I'm not having to translate everything via these arcane hieroglyphics.

I wish people were better at distinguishing between a genuinely held (and valid) opinion and a troll. It is only my opinion.

Reply Parent Score: 1

abraxas Member since:
2005-07-07

These old UNIX tools were terific in their day when they were the only way of doing things. But I think the fact that they continue to get so much air time has more to do with the fact that it's fun play with them. They're like crossword clues.


I think it's because most people still think that bringing Python into the equation for simple formatting and extracting information from output is overkill. If I'm just writing a simple filter to be used between the output of one program and the input of another program on my own machine then I'm just going to use the shell, sed, and awk. If I want to distribute some kind of application that performs all the functions of my script I'm probably going to want to develop it in a language like Python or Perl.

Reply Parent Score: 2

vivainio Member since:
2008-12-26

Modern scripting languages have tremendously powerful string handling functions and they do all this using real words. RE's are there if you need them but you very rarely do.

Depends on how you think (hammer & nails, anyone?). I always think of a regexp solution to any given problem (that I solve in Python) first - typically, I slurp in a string, run re.findall on it, then do a for loop over the resulting tuples.

Regular expressions have the advantage of being insanely fast, and very easy to work with. I agree that for the problems that are trivial enough to solve with awk/sed, regexs may be overkill - you can just do s.replace(), s.split() and s.join().

Reply Parent Score: 1

yiyus Member since:
2006-02-27

If you want to convince me python is better than sed/awk for this kind of tasks you should write all the one-liners in python. Then I will listen to you.

Reply Parent Score: 1