Detecting URLs in a Block of Text

2010-03-31 4 min read Bash

Jan Goyvaerts on <a href="http://www.regex-guru.info/2008/11/detecting-urls-in-a-block-of-text/" target="_blank">Detecting URLs in a Block of Text

In his blog post <a href="http://www.codinghorror.com/blog/archives/001181.html">The Problem with URLs points out some of the issues with trying to detect URLs in a larger body of text using a regular expression.

The short answer is that it can’t be done. Pretty much any character is valid in URLs. The very simplistic <span class="regex">\bhttp://\S+ not only fails to differentiate between punctuation that’s part of the URL, and punctuation used to quote the URL. It also fails to match URLs with spaces in them. Yes, spaces are valid in URLs, and I’ve encountered quite a few web sites that use them over the years. It also forgets other protocols, such as https.

Continue reading

Search & replace with find & ed

2010-03-28 0 min read Bash Learning Linux
\"Computer
Image via Wikipedia

function sr() {

declare pattern replacement name usage
declare -i pvar=0 rvar=0 tvar=0

usage='usage: sr [-t ] [-n name] [-p pattern] [-r replacement] [– ] [dir1 dir2 …]'

# cf. <a href="http://bsdpants.blogspot.com/2007/02/option-ize-your-shell-scripts.html">http://bsdpants.blogspot.com/2007/02/option-ize-your-shell-scripts.html

while [[ "${1:0:1}" == '-' ]] ; do

[[ "${1}" == '–' ]] && { shift; break; } # – marks end of options

Continue reading

Recursive Regular Expressions

2010-03-24 2 min read Bash Fedora Linux

<img src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/yo-dawg-regex.jpg" alt="Yo dawg, I heard you liked regular expressions, so I put a regex in your regex so you can match while you match!" align="bottom" /> The <a class="zem_slink freebase/en/regular_expression" title="Regular expression" rel="wikipedia" href="http://en.wikipedia.org/wiki/Regular_expression">regular expressions we use in our daily lives are actually not that “regular.” Most of the languages support some kind of extended regular expressions that are computationally more powerful than the “<a href="http://en.wikipedia.org/wiki/Regular_expression">regular” regular expressions as defined by the <a href="http://en.wikipedia.org/wiki/Formal_language">formal language theory.

Continue reading

bash – change theme for gtk in gnome and take screenshot from script.

2010-03-24 1 min read Bash Fedora GNOME

I wrote a blog on bash script to change the icon/cursor theme using a bash script. Lets extend the same concept a little more and use the script to change the gtk theme for gnome and at the same time take a screenshot also.

#!/bin/bash
path=&#8221;/tmp/screenshot&#8221;
[[ &#8221;$1&#8221; == &#8221;&#8221; ]] && time=5 || time=$1
[[ &#8221;$2&#8221; == &#8221;&#8221; ]] && (
cd ~/.themes
cont=&#8221;y&#8221;
echo &#8221;Select one of the icon themes&#8221;
echo &#8221;When you like some theme just press Ctrl+c&#8221;
for i in *
do
[[ -d $i/cursors ]] || (
echo &#8221;Now trying …. : $i&#8221;
gconftool-2 –type string -s  /desktop/gnome/interface/gtk_theme &#8221;$i&#8221;
sleep 1
j=$(echo &#8221;$path/$i&#8221;).jpg
import -window root -quality 95 &#8221;$j&#8221;
sleep $time
)
done
) || gconftool-2 –type string -s  /desktop/gnome/interface/gtk_theme &#8221;$2&#8221;

Continue reading

unbound variable – bash completion not working and having issues with other stuff like command not found.

2010-03-23 1 min read Bash Learning Linux

I generally use vi/vim for all my practical purposes of working with text files. And I have all the vi/vim plugins required to work with the files. This causes the following to be in the skeleton for all the bash scripts that I create:

set -o nounset                              # Treat unset variables as an error

With this all the unbound variables as errors and was problem with all the shell scripts that was being sourced in the startup of bash. So all I had to do was remove this from all the startup scripts and then from the skeleton of the bash script in vim :).

Continue reading

Useless Linux Terminal Commands

2010-03-21 1 min read Bash Linux

Useless Linux Terminal Commands Not long ago, I have listed here some useful Linux terminal commands and those that I described as deadly. This time, I decided to gather some commands that I think have no practical use. I know it sounds interesting but you may disagree with me on some of the commands that I&#8217;ll list here as you may find a few of them useful. We can however agree to disagree as long as you explain to us why or how you find them handy.

Continue reading
Older posts Newer posts