Register
It is currently Wed Aug 20, 2014 4:24 pm

Help for a beginner


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Thu Mar 01, 2012 8:02 pm   

Joined: Thu Mar 01, 2012 7:37 pm
Posts: 3
Hey guys I would appreciate some help....I'm a complete noob at this stuff.

What does this command do? Does it return the longest word in the file?
awk '{for(i=1;i<=NF;i++){if(length($i)>length(a)){a=$i;}}}END{print a}' file


I'm trying to follow the logic, for(i=1; <- this is an assignment to give the i variable the value 1?
i<=NF <- NF is a built in variable? Number of fields in the current record? What does that mean exactly?
I understand i++ (keep looping an incrementing i by 1 each time)

Then we introduce this "a" variable which initially equals the value of the i variable?
And we do some operating using the length keyword (is that a standard command or something?) and ultimately print a?


Top
 Profile  
 PostPosted: Fri Mar 02, 2012 11:20 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 534
hi,

Quote:
i=1; <- this is an assignment to give the i variable the value 1?
yes
Quote:
i<=NF <- NF is a built in variable? Number of fields in the current record?
yes
Quote:
Then we introduce this "a" variable which initially equals the value of the i variable?
yes
Quote:
And we do some operating using the length keyword (is that a standard command or something?) and ultimately print a?
yes

:)


Top
 Profile  
 PostPosted: Sat Mar 03, 2012 2:03 am   

Joined: Thu Mar 01, 2012 7:37 pm
Posts: 3
Hi,
OK so I have an idea about the structure of the code but I still don't know what it does.


Top
 Profile  
 PostPosted: Sat Mar 03, 2012 7:59 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 534
Quote:
Does it return the longest word in the file?
yes

sorry, I forgot this one :)


Top
 Profile  
 PostPosted: Sat Mar 03, 2012 11:48 pm   

Joined: Thu Mar 01, 2012 7:37 pm
Posts: 3
Thank you. I might have more questions later.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP