Friday, February 26, 2010

technology

Section to update with new and upcoming Technology...

Suggest any topics or provide feedback to any post under this post

-------Date 12 Mar 2010----------------

How AWK helps

Command line utility provide to tokenize data and access it in efficient way , are the characteristics of AWK utility.

Today I had some problem in reading and changing system files in C programm , n cause of that code n final out put were disturbed. If you have to write a program in C language to read the file process data modify it , Just think how much LOC is required. :P

it should be minimum 50 (approximately), i can't say because I forgot to do it in older way :). AKW provides a major breakthrough.

To summarize AWK use, consider following 3 parts ,

1. It has BEGIN section
2. Exectutable code
3. END part.

eg. awk 'BEGIN
{
/*Initialization part*/
}
{
/// code which will be used to parse or edit .
}

END
{
/*final computation if any.*/
}

'

with block structure like above, we can parse the any input file , tockenize it line by line. One more thing AWK has upper hand is in very simple to understand who had some knowledge in C programming ,like me :P.

If we need to pass some variable to or get some data from AWK script inside a shell script .. it can be done easily...

e.g.
Passing variable to awk script from shell script .
awk -f ' {print MYvar}' Myvar="HI"
this will print Myvar ie. "HI".

Using print inside awk script we can assign output value to shell script variable.

No comments:

Post a Comment