facebook twitter youtube
awk
by Amit Gupta - one comment

Test string 1: r.search(“I am maintaining http:\\article-stack.com. This will help you to learn.”); Output: http:\article-stack.com Test string 2: r.search(“< a href='http:\\article-stack.com' alt='nothing'>article-stack< /a>“); Output: http:\article-stack.com Consideration: length of domain type is 2-4 and it contains alphanumeric characters. Improve previous RE Valid website name should contains alphanumeric characters and hyphen sign only. And hyphen must not [...]

by Amit Gupta - no comments

I had covered following components in last chapter of common elements ^(Start), $(End), .(Any char), *( zero or more occurrences), +( one or more occurrences) and ?( zero or one occurrences) Range Search Range search let you search for specified characters or their range. You need to enclose all characters with in square brackets as [...]

by Amit Gupta - no comments

If you find yourself weak in regular expression then complete this article patiently. But never forget to read Regular Expression, an introduction with full of examples. Otherwise this article will scare you surely. Example content; < amty > 1st block < / amty> article-stack .com < amty src=""> Tag with attributes < / amty> I [...]

in How & Why - 29 Sep, 2010
by Amit Gupta - 2 comments

Prerequisite Regular expression, in introduction with full of example There are various flavours of Regular Expressions. All the flavours are 80% common. Some languages provide more elements, functions and keywords for efficient searching. Maximum of them have common regular expression elements. You can test them in various languages as follow. AWK JAVA PHP PERL I [...]

by Amit Gupta - no comments

Let’s search txt files in a folder. If you are in widows OS then you will open search and will type ‘*.txt’. If you are using unix then you’ll use ‘ls *.txt’. ‘*’ is commonly used regular expression’s element. Sometimes we called it as wild character. Take another simplest example. Amty*.txt What does above pattern [...]

by Amit Gupta - no comments

We write action in curly braces. But pattern can be written outside. Like; Syntax pattern { action } Example awk ‘NR==52 {print $0;}’ For example you want to remove all spaces & tabs from all fields of a file. Here, first you need to find out text contains spaces & tabs (pattern) only. So you [...]

by Amit Gupta - one comment

We already had discussed about what is AWK, an introduction. Now you need to understand basic structure of AWK command; An AWK command can be broken in three parts. Syntax BEGIN { print “START” } { print } END { print “STOP” } BEGIN, END blocks are optional and run only once. While, in the [...]

in How & Why - 02 Aug, 2010
by Amit Gupta - no comments

I hope all of you are aware with AWK. This example will help you to understand AWK practically. Sample Data: 10-Jul-10 23-Jul-10 : 31-Jul-10 1-Aug-10 : 4-Aug-10 5-Aug-10 Output: Aug,10: 5 Jul,10: 22 Explanation: We can break above commands in 3 parts. First part removes the date. And gives filtered out put like; Jul,10 Jul,10 [...]

by Amit Gupta - no comments

AWK is nothing but a simple and powerful UNIX filter command. You can use it to filter & format contents of a text file or to modify sometimes. For example; count number of entries month wise from below file 10-Jul-10 23-Jul-10 : 31-Jul-10 1-Aug-10 : 4-Aug-10 5-Aug-10 Syntax idea: Basic Complex You can call AWK [...]

in How & Why - 01 Aug, 2010
by Amit Gupta - no comments

Following command will help you to remove all trailing and leading spaces from all fields of a text file. It also remove tab characters. I am assuming that all the fields in input file are separated by “^”. If you are using any other separator then set the value of FS in BEGIN block accordingly.