LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   the 'awk' command. (https://www.linuxquestions.org/questions/linux-newbie-8/the-awk-command-544188/)

iconicmoronic 04-07-2007 11:43 PM

the 'awk' command.
 
I have enrolled in a Linux Certification course and damn this particular book for not being more specific about commands than to give the jist. I wondered if someone might tell me what a "delimiter" is when used in reference to the 'awk' command. An example of usage is:
ls filename | awk -->-F:<-- '/and/{print $2,$6,$9}
where the -F argument is used to change the delimiter from the default, tabs and spaces, to the configuration common delimiter of colon, :.
Also, I wondered, because the book is unclear in its explanation of the 'awk' command if the ' is an argument to say "search" or what exactly does the apostrophe denote to this command?
An example usage is:
ls filename | awk -->'<--/and/{$1}

In either example the arrows point to the appropriate argument/modifier. Thankyou.

IconicMoronic

slakmagik 04-07-2007 11:50 PM

A delimiter is what defines the fields - in other words, what $2, $6 and $9 are are defined as what the delimiter is *not*. So

foo<space>bar<tab>baz

means $1 is 'foo' and $2 is 'bar<tab>baz' if the delimiter is just a space and 'foo<space>bar' and 'baz' if the delimiter is just a tab.

As far as the single quote, there should be a final quote as well and it just protects the awk 'program' from being interpreted by the shell. The 'search' part of it is the '/and/' part, which says to apply the '{}' rule to records matching that expression. Might try checking out the info manual for gawk, which is a form of a published book on the subject.

iconicmoronic 04-08-2007 12:29 AM

thankyou
 
thanks so much. i'll check it out. i should've thought harder, i might've recalled the bit about protecting from shell interpretation. thanks again.

iconicmoronic


All times are GMT -5. The time now is 10:33 PM.