urlencoder

Hi friends,

Previously I had a post regarding url encoding and decoding, This is much improved version of that script. To know more about urlencoding, try this link, http://www.blooberry.com/indexdot/html/topics/urlencoding.htm

#!/bin/bash
# urlencode - program to urlencode/urldecode
# Author: Mohan Raman
# License: Its in public domain.

USAGE="[USAGE]
	urlencode [-e|-d] [-h]
"

HELP="${USAGE}
[DESCRIPTION]
	-e	URLEncode standard input(default)
	-d	URLDecode standard input

[EXAMPLE]
	$ urlencode
	http://www.google.co.in
	http%3A%2F%2Fwww.google.co.in

	$ urlencode -d
	http%3A%2F%2Fwww.google.co.in
	http://www.google.co.in
"

encode()
{
sed -e's/./&\n/g' -e's/ /%20/g' | grep -v '^$' | while read CHAR; do test "${CHAR}" = "%20" && echo "${CHAR}" || echo "${CHAR}" | grep -E '[-[:alnum:]!*.'"'"'()]|\[|\]' || echo -n "${CHAR}" | od -t x1 | tr ' ' '\n' | grep '^[[:alnum:]]\{2\}$' | tr '[a-z]' '[A-Z]' | sed -e's/^/%/g'; done | sed -e's/%20/+/g' | tr -d '\n'; echo
}

decode()
{
sed -n -e's/%\([0-9A-F][0-9A-F]\)/\\x\1/g' -e's/+/ /g' -e's/.*/echo -e "&"/g' -ep | "${SHELL}"
}

DECODE="0"

while getopts "edh" OPTION
do
	case "${OPTION}" in
	d) DECODE="1";;
	h) echo "${HELP}"; exit 0;;
	\?) echo "${USAGE}"; exit 1;;
	esac
done

test "${DECODE}" = "0" && encode
test "${DECODE}" = "1" && decode

Download: urlencoder

Advertisements

freebsdman – script to display ‘man’ pages from freebsd.org

Hi friends,

I love FreeBSD’s Documentation(FreeBSD too), Its one of the top class documentations available for UNIX. I think they are capturing nearly every thing about UNIX.

Previously I’ll go to their man page site “http://www.freebsd.org/cgi/man.cgi”, give the command name and get the man page whatever format I want(pdf is damn good!!). But I thought It will be useful if I have an alternative to that *crap* man command in my ‘Ubuntu’ so that I can get all the ‘man’ pages available for Entire Unix family.

Somewhere I saw a small script which gets input from user and generating a URL with GET method parameters and connecting with the server using ‘curl’. Then I decided to do the same thing with my freebsd server, here is the result, a script which will get command name and display the man page, it can be used to get the pdf document also.

USAGE:
        freebsdman [-a 0|1] [-s section] [-d distro]
                [-f format] [-o] [-h]

DESCRIPTION:
        -a 0|1          do 'apropos' search(1-enable, 0-disable)
        -s section      select man section(1-8)
        -d distro       distribution name
        -f format       appropriate format
        -o              list available values for other options.
        -h              print this help

EXAMPLES:
        $ freebsdman ps
                will display man page of 'ps' command from latest
                FreeBSD version in terminal(format: ascii).

        $ freebsdman -d 'solaris' -f pdf mpstat > mpstat.pdf
                will generate 'mpstat.pdf' file which contains
                manual page of 'mpstat' from solaris.

        $ freebsdman -o
                will list all valid values for 'freebsdman' options.

        $ freebsdman -d 'x11' X
                will display 'X' manual (note: manual will not be displayed
                without -d 'x11' option)

Download: freebsdman

One day I’ll have FreeBSD in my Lappy :)