Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-20-2009, 09:38 PM   #1
LQ Newbie
Registered: Mar 2009
Posts: 1

Rep: Reputation: 0
help reg. awk command

i am new to awk scripting. i couldn't figure out how this awk script works? can anyone explain how this for loops operate?

#!/bin/awk -f
for( x=1; x<=NF; ++x) {
if( x == 3 ) {
print x, $x

thank you and regards
Old 03-20-2009, 10:50 PM   #2
Registered: Feb 2006
Distribution: CRUX 2.4
Posts: 96

Rep: Reputation: 18
The for loop operates like a c, c++ or java for loop would.

A variable, x, is assigned the value 1 at the beginning of the loop and it is increased by one until it reaches the value of NF. In awk, the NF variable contains the number of fields in a line. Fields are separated by whitespace by default. Run these commands if you don't understand.

ls -ld
ls -ld | awk '{print NF}'
Hope that helps.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows: Which program can track the reg updates at software install and make a reg? frenchn00b General 5 11-20-2008 05:26 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM
Nice surprise Kaffeine plays Reg 1 and Reg 2 disks 1kyle SUSE / openSUSE 1 10-10-2005 05:47 PM
Clarification needed in this reg exp/awk code mselvam Programming 3 07-09-2005 06:26 PM
need clarification in this reg exp/awk code mselvam Linux - General 1 07-08-2005 04:57 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:55 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration