Reading from a specific line in a loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading from a specific line in a loop
# 1  
Old 07-23-2008
Reading from a specific line in a loop

Hello All,

Request you to let me know how to do the below urgently..

Requirement

File A Contains:
for i in file A
DEV1
DEV5
STG1
STG5

File B Contains:
for j in file B
DEV1
DEV5
STG1
STG5


take the first value of i and compare with the other values of j - 4 comparisons

take the second value of i and compare with the other values of j - again 4 comparisons which is not required cos...DEV1 has been already compared with DEV 5 and therefore DEV5 need not be compared with DEV1 again...

Therefore we need to have a logic like...

DEV1 should read lines below it in j
DEV5 should only compare lines below it in j
and so on...

and do i implement this logic....how do i tell the inner loop to do this in UNIX..

Please help...

THank you
# 2  
Old 07-23-2008
What you're trying to do is either a homework problem, or else so terribly-defined as to defy any hope of getting a productive answer.

Let's examine the possibilities:
1) Your listed files are the extent of the data: Seriously? You're worried about performance when comparing four entries to four other entries?
2) Your listed files aren't the full extent of the data: You're worried about performance, but you're doing this as a shell script?
3) You're doing line-by-line comparisons: diff
4) You're looking for an entry in one file that doesn't exist in the other: sort | uniq | diff
etc., etc.

Please go into more detail about what you want and we'll be happy to assist, but your current post is doing neither you nor us any good. Lastly, a point of etiquette: "Request you to let me know how to do the below urgently.." is not useful. Unless you're paying for advice, you don't get to set the timetable.
# 3  
Old 07-24-2008
Hey BMDan,

Apologies...for the same..

To clear your doubts..
1. It is not the performance i am worryin about
2. I am trying to reduce the number of comparisons as both the files contain the same data
3. if file a and b have 4 lines each we would be having 16 comparisons...but since file a and b are similar... there would comparisons like line1 = line3 and also line 3 = line1 .. we may have a single comparison rather than both as line1=line3 or line3=line1 both are the same..

Do let me know if there is any way I can implement this...

Thanks and Regards
Kaushik
# 4  
Old 07-24-2008
Thanks folks..

I got it...

Check out this:

https://www.unix.com/shell-programmin...#post302096581
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading line by line from live log file using while loop and considering only those lines start from

Hi, I want to read a live log file line by line and considering those line which start from time stamp; Below code I am using, which read line but throws an exception when comparing line that does not contain error code tail -F /logs/COMMON-ERROR.log | while read myline; do... (2 Replies)
Discussion started by: ketanraut
2 Replies

2. Shell Programming and Scripting

Reading line in while loop

Hello Team, i have to read line by line in a while loop, and the input file has:. # The script will start cppunit test application to run unit tests. -LD_LIBRARY_PATH=$CPPUNIT_HOME/lib:\ +LD_LIBRARY_PATH=$VOBTAG/SS_UnitTest/lib:\ $VOBTAG/SS_BFD/BFDSCLI/build:\ ... (7 Replies)
Discussion started by: chandana hs
7 Replies

3. Shell Programming and Scripting

While loop is not reading next line in the file when IF condition is used.

Hi Guys I am new to scripting.Please forgive for asking basic questions. I want to write a script to check whether the logs are getting updated in last 15 mins. cat server 192.168.1.6 192.168.1.7 cat list 192.168.1.7 /logs/logpath1 192.168.1.7 /logs/logpath2 192.168.1.6... (4 Replies)
Discussion started by: vdurai
4 Replies

4. Shell Programming and Scripting

Read file using while loop not reading last line

I have written a script to read the file line by line. It is reading and printing the lines. But it is coming out of loop before reading last line. So I am not able to print last line. How do I solve it. (6 Replies)
Discussion started by: dgmm
6 Replies

5. UNIX for Dummies Questions & Answers

Reading a specific line from a file

Hi All, I am having 100 lines a text file say a.txt. I want read the 'nth' line from that file inside a script. Kindly tell us how to that. (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

6. Shell Programming and Scripting

Update a specific line in a file while reading sequentially

All, I know this is a very naive question but I could not find a way to get this working! I have a file with values like input.file Value1 Value2 server1/mylogin,mypasswd Value3 Value4 And in my code, I am reading the file line by line and processing it. #! /bin/ksh... (6 Replies)
Discussion started by: bharath.gct
6 Replies

7. Shell Programming and Scripting

Reading data from a specific line in a text file

Hello, I have a problem which is giving me headache for days, can some please help. Please see code and text fiel below. Please see text in red for the problem I am facing # Program gets an input x from user while read line ; do echo... (4 Replies)
Discussion started by: jermaine4ever
4 Replies

8. Shell Programming and Scripting

Reading data from a specific line in a text file

hello, I have got the following problem that I am hoping someone can help with please. 1. I have got the following text file (below) , the columns data are 'Test Day', 'Board', 'Betting Number'. TEXT FILE ============================================ 1 3 02-01-27-28-29-30 0 1... (1 Reply)
Discussion started by: jermaine4ever
1 Replies

9. Shell Programming and Scripting

while loop not reading last line

hi all, i have a while loop which i am using to read lines into an array: k=0 exec 10<file while read LINE <&10; do ARRAY=$LINE ((k++)) done exec 10>&- echo ${ARRAY} for some reason when i display the array it is not showing the last row in the file. any help appreciated. (1 Reply)
Discussion started by: npatwardhan
1 Replies

10. Shell Programming and Scripting

reading specific line from file

Hi all... I not a expert unix script programmer, Kindly adjust. My requirement is that, i have a file which contains the about 10 lines - say 1 2 3 ... 8 war of the worlds: => text in this line 9 9000,80,78,77,334,445 => this line contains some numbers separted by commas 10 ... (10 Replies)
Discussion started by: cool_boss2121
10 Replies
Login or Register to Ask a Question