Computing.Net > Forums > Linux > awk

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

awk

Reply to Message Icon

Name: Br1an
Date: October 24, 2002 at 07:25:40 Pacific
OS: Linux
CPU/Ram: 256
Comment:

Hi,
I want to print out ALL the words that appears more than N times from a file call "foo.txt", this is what i got:
foo.txt:
a
b
c
e
g
o
z
a
g
a
a
a
(assume that foo.txt only has 1 coloumn)
now this is the command i got to do the job:
(note that i asume that N=2 in this case)
cat foo.txt | grep -v grep | grep -v awk|
awk '{print $NF}' | sort | uniq -c | awk '$1 > 2'

however, if i put this in a script and i want to replace "2" by $variable, awk does not understand it cos $variable does not get imported ti AWK program... !!!!
I heard that there is a way to pass a variable as an argument to AWK, right ? If so, i certainly can pass $variable to awk in this case. IF anyone knows about this, please let me know ASAP
Thanks
Brian



Sponsored Link
Ads by Google

Response Number 1
Name: Sean Miller
Date: October 24, 2002 at 08:30:13 Pacific
Reply:

Try

cat foo.txt | sort | uniq -c | awk -v x=4 '{ if ( $1 > x ) print $2 }'

replace x=4 with x=$shell_var to make it an input in the script.

Sean


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: awk

using sed or awk to remove and add www.computing.net/answers/linux/using-sed-or-awk-to-remove-and-add-/24313.html

parsing: perhaps sed and awk??? www.computing.net/answers/linux/parsing-perhaps-sed-and-awk/21349.html

awk? grep? www.computing.net/answers/linux/awk-grep-/1686.html