second line of the file

Im very sorry.. for that typo

I copy pasted the above program..

The following is output :

/usr/local/mano$ sh rpomon.sh

0

FIRST and SECOND ... were not printed.. the result was printed.

I used this script.. The output was 0... FIRST and SECOND variables are not printed at all.

if you mean l not |

#! /bin/bash

FIRST=`awk 'BEGIN{FS="l"}NR==1{print $1}' /temp/temp.txt`
SECOND=`awk 'BEGIN{FS="l"}NR==2{print $1}' /temp/temp.txt`
echo $FIRST
echo $SECOND
((str=$FIRST+$SECOND))
echo $str

sorry
i am very poor at english

I presume its a 'l' "small L"

With this script I'm facing the same problem

Im not able to see the $str printed on the screen.

output :

1226051203
1226051162

/usr/local/mano$

Im confused why str is a blank line.. instead of the difference between two variables.

Please post the results of the following commands:

which ksh
uname -a

And the content of your source file.

mano-desktop:/usr/local/mano$ uname -a
Linux mano-desktop 2.6.24-19-generic #1 SMP Wed Jun 18 14:43:41 UTC 2008 i686 GNU/Linux

mano-desktop:/usr/local/mano$ which ksh

This file get updated according to the system time of two nodes.

mano-desktop:/usr/local/mano$ cat /tmp/temp.txt
1226052103l
1226052062l

mano-desktop:/usr/local/mano$ cat rpo.sh
#!/bin/ksh
awk 'NR<=2{print $1}' FS='|' ORS=' ' /tmp/temp.txt |read FIRST SECOND
echo $FIRST
echo $SECOND
res=$(( FIRST + SECOND ))
echo $res
mano-desktop:/usr/local/mano$ sh rpo.sh

0
mano-desktop:/usr/local/mano$

And This was there other script suggested by LifeGeek

mano-desktop:/usr/local/mano$ cat rpomon.sh

#!/bin/sh

FIRST=`awk 'BEGIN{FS="l";OFS=" "}NR==1{print $1}' /tmp/temp.txt`
SECOND=`awk 'BEGIN{FS="l";OFS=" "}NR==2{print $1}' /tmp/temp.txt`
echo $FIRST
echo $SECOND

((str=$FIRST-$SECOND))
echo $str

mano-desktop:/usr/local/mano$ sh rpomon.sh
1226052103
1226052062

mano-desktop:/usr/local/mano$

i modified #23
please check #23

I think the Field seperator is actullay should be FS=" ".

As /tmp/temp.txt will just contain numbers in each line which get updated continously.. No characters inside.

Am I right ?

sh rpomon.sh

execute like this :
./rpomon.sh

geek was rigth , i didn't notice you use bash , ..

$ FIRST=$(awk 'NR==1{print $1}' FS='l' ORS=' ' /temp/temp.txt)
$ SECOND=$(awk 'NR==2{print $1}' FS='l' ORS=' ' /temp/temp.txt)
$ echo $SECOND
1226052062
$ res=$(( FIRST - SECOND ))
$ echo $res
41

Can you explain ur changes ?? I tried with the same, str is printed as a blank line. :frowning:

Your so helpful.. Taking so much time off.

Thanks very much

Oh ya !!! Great I got it with ./rpomon.sh...

I dont know how does it matter ?? Can you explain ??

instead of sh rpomon.sh

execute like this :
./rpomon.sh

it works in ksh and bash

difference between bash(bourne again) and sh(bourne)

working
bash rpomon.sh
./rpomon.sh

not working
sh rpomon.sh

bash is improved version of bourne(sh)

i also learned a lot of things from these posts
thank you meetmano143
thank you Klashxx

OP=- ; sed -e "$!N;s/\n/$OP/g" -e "s/[^0-9$OP]*//g" /tmp/tmp.txt | bc

try this, change op to + or -

just works for two lines

FILE=/tmp/tmp.txt
FRIST=$(head -1 $FILE)
SECOND=$(tail +2 $FILE | head -1)
STR=$(((FRIST + SECOND)))
echo $STR