Extracting data from an XML/HTML node Edit

In this example, you need to extract the data between <p>...</p>. Replace as needed

 % echo '<p>Lorem ipsum dolor sit amet.</p>' | sed 's/.*<p>\(.*\)<\/p>.*/\1/'
 Lorem ipsum dolor sit amet.

Extracting an attribute from an XML/HTML node Edit

In this example, src is the attribute that you need. Replace as needed.

 % echo '<script src=""></script>' | sed 's/.*src=["]\(.*\)["].*/\1/'

Removing carriage return characters (^M) from DOS/Windows files Edit

tr -d \\r < dosfile > newfile

Trimming whitespaces Edit

 echo "        foobar      " | sed 's/^[[:space:]]*\(.*\)[[:space:]]*$/\1/'

Remove comments and blank lines from configuration files Edit

grep -v -e '^[[:blank:]]*#' -e '^$' config_file.conf

Determining the parent interface of a cloned wlan device Edit

# note: may be applicable to FreeBSD only
/sbin/sysctl 'net.wlan.0.%parent' | /usr/bin/sed 's/.*: \(.*\).*/\1/'

Ignore non-matching lines in sed Edit

sed -e 's/.../.../;tx;d;:x'

Show modifies lines only using diff Edit

diff --unchanged-line-format= --old-line-format= --new-line-format='%L' a b

Remove filename extensions to all files in current directory Edit

for i in `ls *`; do
    mv $i ${i%%.*};