second line of the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting second line of the file
# 22  
Old 11-06-2008
Quote:
Originally Posted by lifegeek
Code:
#! /bin/bash

FIRST=`awk 'BEGIN{FS="|";OFS=" "}NR==1{print $1}' /temp/temp.txt` 
# NOT     FIRST=1226045443l     BUT    FIRST=1226045443
SECOND=`awk 'BEGIN{FS="|";OFS=" "}NR==2{print $1}' /temp/temp.txt`
# NOT     SECOND=1226045402l     BUT     SECOND=1226045402

((str=$FIRST+$SECOND))  #or str=$((FIRST+SECOND))
echo $str

or
Code:
#! /bin/bash

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

let str=$FIRST+$SECOND
echo $str

Quote:
Originally Posted by Klashxx
Umm.. typo,use:
Code:
#!/bin/ksh
awk 'NR<=2{print $1}' FS='|' ORS=' ' /tmp/temp.txt |read FIRST SECOND
echo $FIRST
echo $SECOND
res=$(( FIRST + SECOND ))
echo $res

I used this script.. The output was 0... FIRST and SECOND variables are not printed at all.
# 23  
Old 11-06-2008
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

Last edited by lifegeek; 11-06-2008 at 06:07 AM..
# 24  
Old 11-06-2008
Quote:
Originally Posted by Klashxx
This a useless use of awk.
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.
# 25  
Old 11-06-2008
Quote:
Originally Posted by meetmano143
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:
Code:
which ksh
uname -a

And the content of your source file.
# 26  
Old 11-06-2008
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$
# 27  
Old 11-06-2008
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$
# 28  
Old 11-06-2008
i modified #23
please check #23
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

2. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

3. Shell Programming and Scripting

Replace line in file with line in another file based on matching string

HI Can any one guide me how to achieve this task. I have 2 files env.txt #Configuration.Properties values identity_server_url = http://identity.test-hit.com:9783/identity/service/user/register randon_password_length = 6 attachment_file_path = /pass/temp/attachments/... (1 Reply)
Discussion started by: nikilbr86
1 Replies

4. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

5. Shell Programming and Scripting

Match a line in File 1 with Column in File 2 and print whole line in file 2 when matched

Hi Experts, I am very new to scripting and have a prb since few days and it is urgent to solve so much appreciated if u help me. i have 2 files file1.txt 9647810043118 9647810043126 9647810043155 9647810043161 9647810043166 9647810043185 9647810043200 9647810043203 9647810043250... (22 Replies)
Discussion started by: mustafa.abdulsa
22 Replies

6. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

7. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

8. UNIX for Advanced & Expert Users

how do you parse 1 line at a time of file1 ie. line(n) each line into new file

File 1 <html>ta da....unique file name I want to give file=>343...</html> <html>da ta 234 </html> <html>pa da 542 </html> and so on... File 2 343 234 542 and so on, each line in File 1 one also corresponds with each line in File 2 I have tried several grep, sed, while .. read, do,... (4 Replies)
Discussion started by: web_developer
4 Replies

9. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies
Login or Register to Ask a Question