≡ Menu

regular expressions

WordPress Rename Image URL For a CDN Usage

Recently, we moved all our static assets to a CDN (Content Delivery Network) as described here. However, we have over 8000+ old blog posts and we need to point static images url to our CDN account hosted at http://MyACCOUNT.cloudfront.net/images/ folder. How do I rename all image urls stored in wordpress posts? How do I offload static images to a CDN urls under WordPress?
[click to continue…]

nginx: Send HTTP User Agent Requests To Specific Backend Server

I've tons of images, css and javascript hosted at backend server IP and How do I make sure nginx reverse proxy load balancer always send all http_user_agent requests coming from "Mozilla" to server and MSIE to server only?
[click to continue…]

Bash String Comparison: Find Out IF a Variable Contains a Substring

How do I determine whether a variable called spath="/srv/www/cyberciti.biz/https" contains a substring called "cyberciti.biz"?
[click to continue…]

Regular Expressions In grep

How do I use the Grep command with regular expressions on a Linux and Unix-like operating systems?
[click to continue…]

Sed Find and Display Text Between Two Strings or Words

Q. How do I find the text between the strings FOO and BAR inclusive using sed command line option?
[click to continue…]

Delete text or paragraph between two sections using sed

Q. How do I use sed for selective deletion of certain lines? I have text as follows in file:
Line 1
Line 2
Line 4

I would like to delete all lines between WORD1 and WORD2 to produce final output:
Line 1
Line 2

A. For selective deletion of certain lines sed is the best tool. To print all of file EXCEPT section between WORD1 and WORD2 (2 regular expressions), use
$ sed '/WORD1/,/WORD2/d' input.txt > output.txt

Shell script to remove Javascript code

Here is my small script that reads all *.html files and removes javascript (script download link).

# for loop read each file
for f in $FILES
# replace javascript
sed '/<script type="text\/javascript"/,/<\/script>/d' $INF > $OUTF
/bin/cp $OUTF $INF
/bin/rm -f $OUTF

Above shell script removes all occurrence of javascript.