Welcome to MSDN Blogs Sign in | Join | Help

Terry Zink's Anti-spam Blog

Protecting your mail from the scum of the internet
New Year's Resolution Update - Learning Unix better

Earlier this month I made a New Year's Resolution, that I'm going to learn to use unix a little bit better.  Well, so far I've made some good progress as in the past week I have been starting to get used to the sed command.

I find it quite handy; how did I ever get along without it?  The one thing that's annoying is that it isn't pcre-compliant.  That would make it a lot easier for me to use.  I end up having to string multiple sed commands together in order to get it to work properly.

I understand there is a pcrsed command, but it's not installed on the machine I use at work where it would be useful to me.

Posted: Friday, January 26, 2007 5:20 PM by tzink
Filed under:

Comments

DQ said:

If you know Perl, try using "perl -pe" instead.

It's *much* more flexible and s/foo/bar/ which is

all most people do with sed works fine.  Most other

basic sed operations can be done one way or another

and it's much more powerful (perl regular

expressions are just one example).

perl -pe 's/foo/bar/' is the same as sed 's/foo/bar/'

"perl -lne" or "perl -ne" is another great command.

For example:

perl -lne 'print $1 if /foo=([\w.-]+)/' will print

some stuff coming after "foo" on the line.  This

could also be done with s// but you can do stuff

like this which is handy:

perl -lne '$x += $1 if /(\d+)/; END { print $x; }'

Some people use awk for stuff like that, but it's

easier to just use perl, I think.

# January 27, 2007 12:26 AM

tzink said:

Thanks a lot for the tip!

# January 27, 2007 3:39 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker