LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-13-2006, 07:38 PM   #16
0aniel
LQ Newbie
 
Registered: Nov 2005
Posts: 19

Original Poster
Rep: Reputation: 0

What does the code and what does it do, if you could explain as Im a newbie to all this scipt writing.

Cheers

..
 
Old 02-13-2006, 08:11 PM   #17
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
It tells awk to treat an empty line as a record separator (RS),
a line-feed (\n) as a field-separator (FS) and two line-feeds
as an output field separator (OFS).
 
Old 02-13-2006, 10:59 PM   #18
Rufus T. Firefly
LQ Newbie
 
Registered: Feb 2006
Location: Hermosa CA
Distribution: Fedora
Posts: 8

Rep: Reputation: 0
Although you should learn how to use RS/FS/OFS -- (as pointed out up-thread) here's a down and dirty way to get around setting RS/FS/OFS (use defaults) -- this is untested and assumes there is only one blank line between groups of records, like this ...

10
20
30
40

50
40
30
20

etc
etc
etc

BEGIN {
while(getline <"data.txt" >0){
if($0 == ""){print sum; sum = 0}
sum+=$0
}
#print sum
#^^^^^^^^
# uncomment this line if the last line in your
# data file is not a blank line.
close("data.txt")
}

It might also be important to point out that AWK is not a one-size-fits-all language nor is it intended to be written once and played everywhere. Each distribution (awk, mawk, gawk, tawk etc) and each platform (linux, unix, win, mac) all have their own personalities and behaviours. It makes it easier to answer an AWK question when the distribution is known. Just a heads up.

Last edited by Rufus T. Firefly; 02-14-2006 at 11:05 AM.
 
  


Reply



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
Quick Question? Mistro116@yahoo.com Programming 4 11-13-2005 12:03 PM
quick question Squall__99 Mandriva 3 06-01-2005 03:13 PM
Quick question... b00sted Slackware 1 12-27-2004 11:20 PM
Question Concerning ISO's and one quick question. evrae Linux - Software 2 06-21-2004 03:53 AM
samba smb.config question (quick question) TheDOGG Linux - Networking 1 03-02-2004 07:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:39 PM.

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
Open Source Consulting | Domain Registration