ur code works perfectly,but the thing it takes the count as from 0 but i want is it should take count as from 1
Code:
Enter file name
file3
Enter the number
4
count0
biggest no is 6
count1
biggest no is 100
count2
biggest no is 1000
count3
biggest no is 16
total count is 4
this is the output given by the program
but what i need is
Code:
Enter file name
file3
Enter the number
4
count1
biggest no is 6
count2
biggest no is 100
count3
biggest no is 1000
count4
biggest no is 16
total count is 4
Help me plzzzzzzzzzzz
And plzzzzzzzzzzzzzzzzz explain me program also
Its urgent PLzzzzzzzzzzz rpy me as soon as possible
Tanx!!!!!!
Last edited by Franklin52; 02-16-2010 at 06:59 AM..
Reason: Please use code tags!
Replace the awk line with this in the shell script:
Code:
awk -v count=$n 'BEGIN{ i=0; } {k = $1; for (j=1; j<count; j++) {getline; if ( $1 > k ) k = $1; } print "count" ++i; print "biggest no is " k} END {print "total count is " i}' $file
As for what it means... This says set the awk internal variable count to the input
Code:
-v count=$n
This tells awk to initialize i to 0
Code:
BEGIN{ i=0; }
This is the beginning of a clause that says set variable k to the value of the first field of the input line. it will be done for every line.
Code:
{k = $1;
This bit says check each of the following count-1 lines to see if the value is greater than the current k (high) value. if it is, the it becomes the new k.
Code:
for (j=1; j<count; j++) {getline; if ( $1 > k ) k = $1; }
This prints out the biggest value (k) and ends the loop
Code:
print "biggest no is " k}
This is executed when we run out of input and prints the counter
#!/bin/bash
echo "Enter file name"
read file
echo "Enter the number"
read n
awk -v count=$n 'BEGIN{ i=0; } {k = $1; for (j=1; j<count; j++) {getline; if ( $1 > k ) k = $1 } print "count" i; i++; print "biggest no is " k;} END {print "total count is " i}' $file > output
output
Code:
Enter file name
myfile
Enter the number
4
vi output
count0
biggest no is 260
count1
biggest no is 100
count2
biggest no is 3
count3
biggest no is 8
count4
biggest no is 44
count5
biggest no is 7
count6
biggest no is 100
count7
biggest no is 6000
total count is 8
In the above output what i need is
output
Code:
Enter file name
myfile
Enter the number
4
vi output
count0
smallest no is 10
biggest no is 260
count1
smallest no is 1
biggest no is 100
count2
smallest no is 1
biggest no is 3
count3
smallest no is 2.7
biggest no is 8
count4
smallest no is 3
biggest no is 44
count5
smallest no is 4
biggest no is 7
count6
smallest no is 03
biggest no is 100
count7
smallest no is 160
biggest no is 6000
total count is 8
i belive my question would have been clear
plzzzzzzzzz anyone help me
kindly requesting!!
Thanks!!
---------- Post updated at 11:41 AM ---------- Previous update was at 01:07 AM ----------
hi
the program i tried is
Code:
#!/bin/bash
echo "Enter file name"
read file
echo "Enter the number"
read n
awk -v count=$n 'BEGIN{ i=0; } {k = $1; m = $1; for (j=1; j<count; j++) {getline; if ( $1 > k ) k = $1; if ( $1 < m ) m = $1;} print "count" ++i; print "smallest is " m; print "biggest no is " k} END{print "total count is " i}' $file
Enter file name
data
Enter the number
4
count1
smallest is 2.3
biggest no is 6
count2
smallest is 0.3
biggest no is 100
count3
smallest is 3
biggest no is 2000
count4
smallest is 8
biggest no is 2000
count5
smallest is
biggest no is 12
total count is 5
while there is left only one number in last i want the output like this given below
Code:
.
.
.
.
.
.
count5
only one number is left 12
total count is 5
then while taking 5set of no's my output is like this
Code:
Enter file name
data
Enter the number
5
count1
smallest is 0.3
biggest no is 6
count2
smallest is 2.6
biggest no is 2000
count3
smallest is 3
biggest no is 10
count4
smallest is
biggest no is 2000
total count is 4
but it should display like this as given below
Code:
.
.
.
.
.
count4
smallest is 12
biggest no is 2000
total count is 4
plzzzzzzzzzz anyone help me
Tanx in advance
Last edited by Franklin52; 02-16-2010 at 07:01 AM..
Reason: Please use code tags!
I am new to ksh scripts. I would like to be able to read a file line by line from a certain line number. I have a specific line number saved in a variable, say $lineNumber. How can I start reading the file from the line number saved in $lineNumber? Thanks! (4 Replies)
hello guys,
I'm struggled to get a number from a very long text file.
NAtoms= 33 NActive= 30 NUniq= 23 SFac= 1.00D+00 NAtFMM= 60 NAOKFM=F Big=F
Integral buffers will be 131072 words long.
Raffenetti 2 integral format.
The number 33 is what I wanted, always follows NAtoms=... (5 Replies)
Hi all,
I have a file sample.txt
abc
asd
adf
daf
adw
add
adv
wdf
I want to control the number of lines to read
Like if i give input as ./script_name 2 5
required output
asd
adf
daf (2 Replies)
Hello All,
i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file.
Any inputs are appreciated
... (3 Replies)
Hello Everyone.
I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below:
if ; then
if ; then
tail +$1 $3 | head -n $2
else
... (5 Replies)
Hello, I'm trying to create a BASH file that can read all the files in my working directory and tell me how many words and lines are in that file. I wrote the following code:
FILES="*"
for f in "$FILES"
do
echo -e `wc -l -w $f`
done
My issue is that my file is outputting in one... (4 Replies)
I have a file with a list of config files numbered on the lefthand side 1-300. I need to have bash read each lines number and assign it to a variable so it can be chosen by the user called by the script later.
Ex. 1 some data
2 something else
3 more stuff
which number do you... (1 Reply)
Hi Guys,
I am new to unix.
Actually i want help in writing an single command where
i can actually read specific line number in file where the line number will be passed to command as parameter.
ex.
1 a
2 b
3 c
4 d
And to my command i pass as 2.
so i should get output as 2 b
... (15 Replies)
Hi All,
I want to read one number from the file.
Only one number will be there in the file.
then i have to increment the number in my script and put it back in the same file.
Is it possible?
Can anybody help me?
Thanks,
Vinay (6 Replies)
hi,
I am a begginer in unix and i want to know how to open a file and read it and separate the numbers & words and storing it in separate files, Using shell scripting.
Please help me out for this.
Regards
S.Kamakshi (2 Replies)