Search found 93 matches

by berserker
06 Jan 2014 08:24
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Some common Awk Variables

Awk has some internal variables that you should be familiar with for parsing string and files. 1) NR 2) NF 3) FS 4) RS 5) ORS 6) OFS 1) NR NR stands for number of input records awk has processed since the beginning of the program's execution. For example, you want to find the line count of a file C:...
by berserker
06 Jan 2014 07:36
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Re: Awk - A nifty little tool for text manipulation and more

substr($0,2,5) just says to get the characters starting at position 2, ending at position 5 of the current record. This starts at position 2 for a length of 5 characters, no? yes. good spot. Will change. I noticed a couple of minor points here and there in your explanations: The following is echoin...
by berserker
06 Jan 2014 07:33
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Awk Flow control

Making decisions are part of our thought process every day. If you want to tell the computer to do something then the language must provide if/else constructs for that. Awk provides the usual if/else/else if constructs that most languages have. C:\>awk "BEGIN{ b=2; if( b==2 ) print \"it is...
by berserker
06 Jan 2014 07:20
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Awk arrays

Most programming language support data structures such as arrays that can be used to stored similar collection of items, instead of individual variables. Awk has arrays too and its called associative arrays. That means each array is a collection of pairs, called, index and value . Here are simple ex...
by berserker
06 Jan 2014 06:59
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Awk Loops

Awk loops works the same as those in C language. Here I touch 2 of the most common loops , 1) for loop 2) while loop The syntax for a "for" loop in awk is this for (initialization; condition; increment) body eg to generate a range of numbers from 1 to 9 C:\>awk "BEGIN{ for(i=1;i<10;i+...
by berserker
06 Jan 2014 06:29
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Printing in awk

awk provides at least 2 forms of printing to output, 1) print 2) printf and 3) sprintf() 1) print. The basic statement to display output to the user is the print statement. It should be too difficult to understand how to use it. Just print "your string" Sometimes you also can redirect to a...
by berserker
06 Jan 2014 06:02
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Re: Awk - A nifty little tool for text manipulation and more

foxidrive wrote:It would be useful to also show there how to seed the randomize function, otherwise every time you execute that command it will show the same number. Newbies might scoff. ;)

good point. added.
by berserker
06 Jan 2014 05:47
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Simple string manipulation

Here I cover simple string manipulation in awk using its in-built string functions 1) Getting part of a string - substring-ing 2) Getting index of a string 3) Splitting a string 4) Uppercase and lowercase 1) Getting part of a string awk provides the substr() function to get part of a string, for exa...
by berserker
06 Jan 2014 05:22
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Operators

awk provides the usual maths operators to help you perform calculations in your script. Here I only list some that are commonly used. Exponents x ^ y x ** y Add, minus, divide, multiply -> +, - , / , * Modulus : % x++ , ++x : post and pre increment operators x-- , --x : post and pre decrement operat...
by berserker
06 Jan 2014 04:55
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Re: Awk - A nifty little tool for text manipulation and more

That's useful. Keep the primer going. BTW, the code output above after Issuing the same commands as before but pass ',%#' to -F is the same as the earlier output, which doesn't make as much sense to a newbie reading the primer. You kind of expect something different. Maybe a different text to show ...
by berserker
06 Jan 2014 04:54
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Length of a string or record

Often we need to get the length of a string or a line of record in the file. awk provides the length() function to do this. For example C:\>echo "test"| awk "{print length}" 6 why is it 6 and not 4 ? This is because the "echo" command in DOS "counts" the doubl...
by berserker
06 Jan 2014 04:33
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Parsing Structured Text

One common task almost everyone does is getting information from files. If you have a field delimited text file to parse, then awk might be just the tool you need. For example, if you have this simple csv file where the delimiter is "|" C:\>type myFile.txt 1|2|3|4|5 6|7|8|9|10 a|b|c|d|e an...
by berserker
06 Jan 2014 04:14
Forum: DOS Batch Forum
Topic: Awk - A nifty little tool for text manipulation and more.
Replies: 30
Views: 12716

Awk - A nifty little tool for text manipulation and more.

awk has been around since the unix days in the 70s and has been a standard tool in most unix-like OS. It is primarily used for text and string manipulation. The GNU awk is one of the most widely used awk version nowadays and now its also ported to the windows OS so its now convenient to use it as pa...
by berserker
06 Jan 2014 01:44
Forum: DOS Batch Forum
Topic: two findstr questions
Replies: 27
Views: 10346

Re: two findstr questions

grep has its origin in the unix world. you can go to any unix or linux forum site to ask. or you can go to stackoverflow.
by berserker
06 Jan 2014 00:44
Forum: DOS Batch Forum
Topic: Bhx 3.1
Replies: 35
Views: 11824

Re: [utility] Bhx 2.1

foxidrive wrote:Read my comment again, the answer is there.

no its not.