Operating System - HP-UX
1832595 Members
3097 Online
110043 Solutions
New Discussion

Hp-ux B.11.11 ksh Scripting .

 
SOLVED
Go to solution
Raj D.
Honored Contributor

Hp-ux B.11.11 ksh Scripting .

Hi I need help for finding out the persons, marks achived , more than 80.

Hp-UX B.11.11 U 9000/800 /usr/bin/ksh

file name: marks.txt

93 Steeve
72 Brocar
43 Minsen
22 Wilsen
77 David
99 Terence
82 Dave
89 Stuwart
78 Vivek
89 Paul
93 Ravi
95 Richard

How to write a script for that ,
I want listing of those name , who is greater than 80.

Does awk or sed help me.

Many Thanks in Advance,

Raj.
----
" If u think u can , If u think u cannot , - You are always Right . "
9 REPLIES 9
KapilRaj
Honored Contributor

Re: Hp-ux B.11.11 ksh Scripting .

cat filename|awk '{ if ($1 > 79) print $2}'

Regds,

Kaps
Nothing is impossible
Raj D.
Honored Contributor

Re: Hp-ux B.11.11 ksh Scripting .


Hey Kapil ,

Thanks , thats works fine.
but can i save the result in a file.
Do i need to do >> or can i use something inside awk.

Thanks so much ,

RajD.
" If u think u can , If u think u cannot , - You are always Right . "
Ralph Grothe
Honored Contributor

Re: Hp-ux B.11.11 ksh Scripting .

Yes you can simply redirect stdout in append mode.
Btw. the prepending cat is redundant.

Since TIMTOWTDI here's a Perl variant that will give you a sorted list of top seats exceeding 80 points

perl -e 'map{printf"%s\t%u\n",@{$_}[1,0]}sort{$b->[0]<=>$a->[0]}grep $_->[0]>80,map[/(\d+)\s+(\w+)/],<>' /path/to/inputdata
Madness, thy name is system administration
KapilRaj
Honored Contributor

Re: Hp-ux B.11.11 ksh Scripting .

cat filename|awk '{ if ($1 > 79) print $2}' > filename.out

Regds,

Kaps
Nothing is impossible
Gordon  Morrison
Trusted Contributor
Solution

Re: Hp-ux B.11.11 ksh Scripting .

Why be AWKward?
grep ^[89][0-9] marks.txt > highmarks.txt

or, if you want them in order:
grep ^[89][0-9] marks.txt|sort -n > highmarks.txt
What does this button do?
Robert Dill
Advisor

Re: Hp-ux B.11.11 ksh Scripting .

Hi Raj,
I like "read":

cat test.in | \
while read a b
do
if [ $a -ge 80 ] ; then
echo $a $b
fi
done | \
sort -n

Good luck,
Bob
Stefan Murariu
New Member

Re: Hp-ux B.11.11 ksh Scripting .

I like also read, so:

while read rank name; do
if [ $rank -gt 79 ]; then
echo "${rank} ${name}"
fi
done
Note for awk:
no need to cat the input file

awk '{ if ($1 > 79) print $2}' input_file > output_file
James R. Ferguson
Acclaimed Contributor

Re: Hp-ux B.11.11 ksh Scripting .

Hi:

Using 'cat' to read and then piping its output to 'awk' or a shell 'read' loop is a needless, utter *waste* of a process.

Instead of:

# cat filename|awk '{if ($1 > 79) print $2}'

Do:

# awk '{if ($1 > 79) print $2}' filename

Instead of:

# cat file | \
while read a b
do
...
done | sort

Do:

# while read a b
do
done < file | sort

Regards!

...JRF...

Peter Nikitka
Honored Contributor

Re: Hp-ux B.11.11 ksh Scripting .

Hi,

@Gordon, @Stefan: what about
100 Gordon

in connection with '/[89]...' ?

I fell better with the compare operator '>'.
mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"