loving perl one-liners

I’ve always been a big perl fan.

Just ran into another case, where I dusted off some old dusty synapses and did a little perl oneliner.

Given a pile of text files, prepend each line of each file with a ‘* ‘ (to make it handy for a markdown list.

find . -name '*.txt' -print0 | xargs -0 perl -pi -e '$_ = "* $_"' 

done and done.

A file like this

line 1
line 2
line 3

now looks like this

* line 1
* line 2
* line 3

And it hit every text file (*.txt) in this directory and below.

If you haven’t played with perl oneliners (or ruby oneliners for that matter) check out these resources:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s