Two Useful Bash Commands to Find and Replace

Some useful shell commands I’ve been using lately.

First one does a print into console of all words match `/media/static` for files in the folder and below that ends with a html file type.

The second one finds all html file types and replaces /media/static/images/yellowcross.png with {% static ‘images/yellowcross.png’ %}

grep -rn "/media/static" . `find . -name "*html"`

find . -name "*.html" -print | xargs sed -i "" "s+/media/static/images/yellowcross.png+{% static 'images/yellowcross.png' %}+g"
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