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

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

Quick tip to change parameters in different files

2010-03-16 1 min read Linux
for i in *.cfg; do mv $i $i.bak;sed \’s/a/b/\’ $i.bak > $i; done

The above command is very useful to change certain regular expressions in couple of files in one directory. This can be used in variety of ways to achieve a lot of things which would normally take some time to do manually.

Some bashrc shorcuts for faster and profiecient directory browsing.

2010-03-10 1 min read Bash Linux

Here are some of the funtions that I have in my bashrc to make my life simple. They are not written by me but mostly taken from other places, but modified by me to some extent to suit my needs. If you know the original creator of these, let me know so I can add the attribution for the same.

This one is very useful.

.. (){
local arg=${1:-1};
local dir=&#8221;&#8221;
while [ $arg -gt 0 ]; do
dir=&#8221;../$dir&#8221;
arg=$(($arg – 1));
done
cd $dir >&/dev/null
}

Continue reading

Bash script to view log and config file in different server and paths.

2010-03-09 1 min read Bash

I was working on a project, where I need to open file from different servers and different paths. I do it with the command:

vim ftp://username@server/path/filename

This is okay when the path is short but when the path gets longer and I have different config files to open from the same path or their associated logs, then it becomes un-necessary typing. So, I did the following:

Have a file with some aliase&#8217;s like the below and source it from the bashrc file:

Continue reading
Older posts Newer posts