LinuxQuestions.org
Review your favorite Linux distribution.
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 12-05-2006, 05:24 PM   #1
Breezend
LQ Newbie
 
Registered: Dec 2006
Posts: 4

Rep: Reputation: 0
Limiting the output of the script


Hi,
am reading this GNU AWK users guide and there is one script connected to sorting. This one :
$0 = tolower($0) # remove case distinctions
# remove punctuation
gsub(/[^[:alnum:]_[:blank:]]/, "", $0)
for (i = 1; i <= NF; i++)
freq[$i]++
}

END {
sort = "sort +1 -nr"
for (word in freq)
printf "%s\t%d\n", word, freq[word] | sort
close(sort)

}

Was wondering how to limit the output? What I mean if I don't need every word but the 50 most frequent. Tried putting the output in the array and then in the for cycle to use the built in function delete
(smth like for(i=var;i>var;i++)delete array[i](where var is the variable given in the command line -v var) )but it's an error: attempt to use scalar as an array. Any suggestions?
P.S. yeap that can be done with Bourne Shell but why then am I reading that awk manual?
P.S.S the book I am reading "awk&sed" does not give any answer to this

Last edited by Breezend; 12-06-2006 at 12:57 AM.
 
Old 12-06-2006, 11:02 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
I have deja vu.

You could pipe the output to "head -n lines"?
 
Old 12-06-2006, 01:15 PM   #3
Breezend
LQ Newbie
 
Registered: Dec 2006
Posts: 4

Original Poster
Rep: Reputation: 0
yeap thanx works perfectly. Topic can be closed
 
  


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
Where is the output from my init.d script? PostPCMan Ubuntu 1 07-03-2006 01:09 PM
Limiting RAM usage in a perl script DanTaylor Programming 2 05-05-2006 02:37 PM
script output spx2 Linux - Newbie 12 12-13-2005 08:44 AM
Limiting ps output stryka Slackware 5 12-07-2005 05:41 PM
limiting page load frequency with a perl cgi script Metroid Programming 0 12-30-2004 10:33 PM

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

All times are GMT -5. The time now is 05:56 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