Live data from Hacker News

Introduction to sed

catonmat.net

31–33 of 33 posts

Re: Introduction to sed

#31
post #19

Earlier quoted context omitted.

On the speed question, I actually find Perl considerably faster than sed in a lot of use-cases, if there's enough processing to dominate the slightly higher startup costs of Perl. For example, at one point I had reason to take a gigantic single-line textfile, and break it into lines based on a specific 3-letter pattern that didn't occur anywhere else: s/ABC/A\nC/g In whatever sed comes with Debian, this took about 10…

The copyright section of sed(1) suggests that the Debian package sed (I'm running wheezy) is Gnu sed 4.2.1[1]. Plan9 sed is also available in the 9base package. I'm running perl 5.12.4 (also from Debian testing). I don't see any significant difference in speed with vanilla 5.14.1 and the commands I mentioned earlier. [1] http://www.gnu.org/software/sed/

Turn on locale UTF-8 for GNU software before benchmarking it to compare with Plan9 software.

GNU stuff gets a speed improvement from assuming single byte characters.

Re: Introduction to sed

#32
post #21

Earlier quoted context omitted.

however, perl has -i, which not all seds do, so those 0.002 seconds you lost to perl will be more than gained by being able to type perl -pi -e 's/foo/bar/' somefile instead of sed 's/foo/bar/' somefile > somefile.tmp && mv somefile.tmp somefile

Sed has -i, too! Well, at least GNU sed.

because GNU is Not Unix

Re: Introduction to sed

#33
post #15

I dont know if this off topic but is there an utlity that can parse C files and print all the function names or local variable names for example. I know it can be done through sed,but a perfect regex for parsing functions and nothing else can be complex and I am wondering if someone has already done it.

Look at what the perl script at http://www.gson.org/egypt/ does -- if you are using gcc, you can compile with certain options to generate info from the source code into an intermediate file and then parse this intermediate file with a script to get the info you need. A bit complex, but useful if you are trying to read through code you are maintaining. A compiler is better than a regex for this, I think, for C. Also c…

I checked out Egypt.It is pretty cool but unfortunately it doesnt seem to have support for Objective C.
Post reply on HN