is there any way to read a line twice in KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting is there any way to read a line twice in KSH
# 1  
Old 01-24-2006
is there any way to read a line twice in KSH

Hi All,

Is there any way to read the previous line in file reading ?
or

is there any way to read a line twice in KSH ?


thanks in advance !!
Srini
# 2  
Old 01-24-2006
Smilie You should just copy the variable, but I suppose this would work:

read line1
echo "$line1" | read line2
# 3  
Old 01-24-2006
I always store the line in the variable prv_line and use it after going to the next line read...

don't think we have unix built in functionality, eager to know if there is one...
# 4  
Old 01-24-2006
My actual proble is :

i have a file as below

AAAAAAAAAAAA
-------------------
-------------------
-------------------
BBBBBBBBBBBBBB
AAAAAAAAAAAAA
-------------------
-------------------
-------------------
-------------------
-------------------
-------------------
BBBBBBBBBBBB
AAAAAAAAAAAA
AAAAAAAAAAAA
AAAAAAAAAAAA
AAAAAAAAAAAA
-------------------
-------------------
-------------------
BBBBBBBBBBBBBB
AAAAAAAAAAAAA
-------------------
-------------------
-------------------
BBBBBBBBBB
AAAAAAAAAAAA
AAAAAAAAAAAA
...

I want the out put be as follows-

AAAAAAAAAAAA
-------------------
-------------------
-------------------
BBBBBBBBBBBBBB
**************
**************
AAAAAAAAAAAAA
-------------------
-------------------
-------------------
-------------------
-------------------
-------------------
BBBBBBBBBBBB
**************
**************
AAAAAAAAAAAA
-------------------
-------------------
-------------------
BBBBBBBBBBBBBB
**************
**************
AAAAAAAAAAAAA
-------------------
-------------------
-------------------
BBBBBBBBBB

I am reading the file using while loop..

1. while first line is AAAAAAAAAA
2,. do
3. until line=AAAAAAAAAAA
4. print line
5. done
6. done

when I use this logic some of the blocks are missing in the output as, the "until loop has already read the AAAAAAA line" (at step 3)

its not going to while loop in the next iteration (Step1) for check condition

Can any body have a fix for this ?

Thanks
Srini
# 5  
Old 01-24-2006
you don't want to repeat "AAAAAAAAAA" ??

can you tell me the actual logic... not getting it.

Last edited by mahendramahendr; 01-24-2006 at 02:56 PM..
# 6  
Old 01-24-2006
file reading issue

Perderabo/ mahendramahender

Hope this will explaing you better



Thanks
Srini

Last edited by Srini75; 01-25-2006 at 11:14 AM..
# 7  
Old 01-25-2006
I tried this on your sample file...
Code:
awk '/Error/{print ORS p;c=3}c-->0;{p=$0}' some.txt

Result...
Code:
Processing uid abc123 tpn
Error on trans: db
FAILURE on uid abc123 during trans
Cannot fetch from the table

Processing uid abc1234 tpn
Error on trans: db
FAILURE on uid abc1234 during trans
Cannot fetch from the table

Processing uid abc1235 tpn
Error on trans: db
FAILURE on uid abc1235 during trans
Cannot fetch from the tabe

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While read -a line not working in ksh

while read -a line; this is not working in ksh. what is the equivalent of this in ksh. read: -a: unknown option (2 Replies)
Discussion started by: archana25
2 Replies

2. Shell Programming and Scripting

Ksh: Read line parse characters into variable and remove the line if the date is older than 50 days

I have a test file with the following format, It contains the username_date when the user was locked from the database. $ cat lockedusers.txt TEST1_21062016 TEST2_02122015 TEST3_01032016 TEST4_01042016 I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Discussion started by: humble_learner
11 Replies

3. 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

4. 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

5. Shell Programming and Scripting

Extract Line and Column from CSV Line in ksh or bash format

Hi, I was doing some research and can't seem to find anything. I'm trying to automate a process by creating a script to read a csv line and column and assigning that value to a variable for the script to process it. Also if you could tell me the line and column if it's on another work ... (3 Replies)
Discussion started by: vpundit
3 Replies

6. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

7. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

8. Shell Programming and Scripting

KSH: Reading a file line by line into multiple arrays

Hi - I have a file that contains data in this format:- #comment value1 value2 value3 #comment value4 value5 value6 value7 #comment value8 value9 I need to read value1, value2 and value3 into one array, value4 value5 value6 and value7 into another array and value8 and value9 into a 3rd... (2 Replies)
Discussion started by: sniper57
2 Replies

9. Shell Programming and Scripting

read a file line by line in ksh

Hi, In ksh we use 'while read line' statement to read a file line by line. In my input file I have 5 spaces appended at the end of each line. When I use while read line statement it chops off the spaces at the end of each line Inp.txt aaaa<five spaces> bbbb<five spaces> cccc<five spaces> ... (3 Replies)
Discussion started by: chella
3 Replies

10. Shell Programming and Scripting

ksh read timeout

any idea on how to timeout the read statement for ksh? for bash u can use read -t option -t timeout Cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has ... (2 Replies)
Discussion started by: ashterix
2 Replies
Login or Register to Ask a Question