LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-20-2009, 09:38 PM   #1
phone_book
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 ) {
continue
}
print x, $x
}
}

thank you and regards
 
Old 03-20-2009, 10:50 PM   #2
nflenz
Member
 
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.

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


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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