Hi
I want to find greater than and min value.
dategrep()
{
varlinenum=$1
varSESSTRANS_CL="$(egrep -n "<\/SESSTRANSFORMATIONINST>" tmpsess9580.txt | cut -d":" -f1)"
echo $varSESSTRANS_CL
}
dategrep 8
Output of the above command is:
I want to find out greater than 8 and min of the above result.
Answer should be : 10
Can anyone help me on above requirement.
Thanks,
Mallik.
$ cat outfile
5
7
10
13
18
21
$ nawk '{if($0>8){print $0;exit}}' outfile
10
$
i want to pass 8 value as parameter. When i am passing parameter it not printing anything.
$ln_num=8
$awk '{if($0>$ln_num){print $0;exit}}' outfile
ygemici
4
what is contents of tmpsess9580.txt ?
if as a parameter ..
$ nawk -v var=8 '{if($0>var){print $0;exit}}' outfile
10
$
ygemici
6
use like this
awk '{if($0>'$ln_num'){print $0;exit}}' outfile
or
awk -v ln_num=8 '{if($0>ln_num){print $0;exit}}' outfile
panyam
7
If the file is not sorted and still you wish to get the "min" value
TESTBOX>awk -v m=9999999999999 '$0>8 && $0<m { m=$0 } END { print m}' outfile
My output is in variable and i want to read that variable and print the required number.
The above solutions are perfectly working with outfile. But I dot want to create file to store values and process that.
This is what i am trying here.
dategrep()
{
varlinenum=$1
varSESSTRANS_CL="$(egrep -n "<\/SESSTRANSFORMATIONINST>" tmpsess9580.txt | cut -d":" -f1)"
echo $varSESSTRANS_CL
echo $varSESSTRANS_CL | awk '{if($1>'$varlinenum'){print $1;exit}}'
}
dategrep 8
Output of the echo $varSESSTRANS_CL is..
5
7
10
13
18
21
echo $varSESSTRANS_CL | awk '{if($1>'$varlinenum'){print $1;exit}}'
this stmt is not working or not printing anything..
echo "$varSESSTRANS_CL" | awk '{if($1>'$varlinenum'){print $1;exit}}'
1 Like