Very Challenging Problem. Please read fully.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Very Challenging Problem. Please read fully.
# 8  
Old 07-19-2008
@RRVARMA
Your script give me
real 0m2.997s
user 0m0.980s
sys 0m1.624s

Replace
Code:
	field7=`echo $j|cut -d "|" -f7`
	field13=`echo $j|cut -d "|" -f13`
	field14=`echo $j|cut -d "|" -f14`
        if [ "${i}" == "${field7}|${field13}|${field14}" ]

by:
Code:
 if [ "${i}" == "$(echo $j | awk 'BEGIN{FS=OFS="|"}{print $7, $13, $14}')" ]

and you will save %43 procesing time using the same resources.
real 0m1.683s
user 0m0.612s
sys 0m0.888s


@cooldude solution demands more memory but is faster.
real 0m0.211s
user 0m0.036s
sys 0m0.004s


@Franklin52 awk solution is the best, but uses a significant amount of memory
real 0m0.005s
user 0m0.000s
sys 0m0.004s
# 9  
Old 07-19-2008
If you really want to speed things up, store the contents of the first file in an array. Then read the records of the second file one by one and compare the seventh, 13th, and 14th records against the array. You can perform the binary search on the array since the array is already sorted. The problem with fpmurphy's solution was that he was constantly invoking cut and reading the file again and again. In my solution, I used ksh's functionality to split the fields in the file, but I am still reading the file again and again. I'm betting the solution I'm proposing will be even faster than Franklin52's.
# 10  
Old 07-19-2008
you're lucky you have not had your thread closed for cross posting if this is he third thread you have started for the same topic
# 11  
Old 07-20-2008
Quote:
Originally Posted by JamesByars
you're lucky you have not had your thread closed for cross posting if this is he third thread you have started for the same topic
Since this thread seems to be the longest of the three that he had started, I am keeping this open and closing the others.
RRVARMA, please adhere to the rules. No double posting or bumping up the posts.
Here are the other threads.
https://www.unix.com/shell-programmin...wk-script.html
https://www.unix.com/shell-programmin...ther-file.html
# 12  
Old 07-20-2008
Hi,

Thanks cooldude, but your script is fetching not only the unique records but also the other records as well.. I'm confused.. Smilie

But its quite faster than the other scripts which i tried.

Thanks vino, for closing other two threads.. Sorry that i didn't know how to close those threads.
# 13  
Old 07-20-2008
I recommend Franklin's solution. But here's another version:
Code:
#!/bin/ksh

if [ $# != 2 ] 
then
exit 1
fi

while read i
do
    while read j
    do
	set -A array $i
	field7=${array[6]}
	field13=${array[12]}
	field14=${array[13]}
        if [ "${i}" == "${field7}|${field13}|${field14}" ]
	then
	print "$j"
	break 
	fi
    done < $2
done < $1

It is the same as the script you posted in your first post, except that I am not using cut to extract fields.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Challenging scenario

Hi, My input file contains 1,2 2,4 3,6 4,9 9,10 My expected output is 1,10 2,10 3,6 4,1 9,10 (6 Replies)
Discussion started by: pandeesh
6 Replies

2. Shell Programming and Scripting

simple but challenging ignore case

Folks - I found this code on the forums to extract a paragraph for a matching pattern but I don't know how to make it ignore case. grep "-ip" is not an option for me as I am on SUSE LINUX. Thanks for ur help. I run this script as below: grep_para.ksh sqlstate < logfile "The end result... (2 Replies)
Discussion started by: beowulfkid
2 Replies

3. Shell Programming and Scripting

Challenging Awk array problem

Hi, I rather have a very complicated awk problem here, at least to me. I have two files. File 1: 607 687 174 0 0 chr1 3000001 3000156 -194195276 - L1_Mur2 LINE L1 -4310 1567 1413 1 607 917 214 114 45 chr1 3000237 ... (19 Replies)
Discussion started by: polsum
19 Replies

4. Shell Programming and Scripting

Need help with this challenging code....

Hello All, I am new to this forum, and the reason I came here is to seek solution from the experts. I have written following wrapper script, it was running fine from past couple of months, until last week. When one of the function in the script which suppose to login through ssh to the... (2 Replies)
Discussion started by: tajdar
2 Replies

5. Programming

A challenging problem involving symbolic links.

Hello, I'm working on an application that bridges together several applications involved in creating a video workflow for editing with digital cinema cameras. The main platform is MacOSX. Because of the nature of some of the utilities for working with this video footage I must spoof filenames... (2 Replies)
Discussion started by: ibloom
2 Replies

6. Solaris

Hostname not fully qualified..

Hi Friends.. I have a small problem with the hostname of my system.I had installed Solaris 10 X86 on Vmware in my windows 2000 system.After booting of my solaris system,if i give check-hostname command it says ,, hostname is not fully qualified ,,change the hostname to hostname.xxx.xxxxxx.com... (3 Replies)
Discussion started by: sdspawankumar
3 Replies

7. Shell Programming and Scripting

Challenging!! Help needed

Hi, I have a script xyz.ksh which accpets two parameters the format of first one is :X_TABLENAME_Y and second one is a digit. I can extract a table name from that parameter and store it in a variable var_tblnm, so if i pass a parameter X_TABLE1_Y the value in var_tblenm is "TABLE1" now i have... (1 Reply)
Discussion started by: hcdiss
1 Replies

8. UNIX for Dummies Questions & Answers

A Challenging situation for the MODERATORS

Well, I hope this way you will respond to my inquiries. I have 4 unix servers,with static ips (though i dont think this is an issue)....i can telnet and rlogin from one to the other....if i FTP from on et othe other and try to execute : cd /user return /user : no such file or... (1 Reply)
Discussion started by: BAM
1 Replies

9. UNIX for Dummies Questions & Answers

A Challenging Situation : i hope the moderators will respond to this problem..

I have the following situation : i have 4 Unix Sco servers, one Windows 2000 server, and an ADSL internet connection. All the servers, that is the 4 unix and the windows server have real static IPs supplied by my ISP. the servers are connected to a Switch , the switch is connected to an... (2 Replies)
Discussion started by: BAM
2 Replies

10. UNIX for Advanced & Expert Users

Very Challenging Question! Need help bad!

I am in desperate need of an answer to this question. I have looked everywhere (even the man pages) and found very little. Solaris has the concept of "plumbing" a network interface. What does this mean? I would be really greatful to whoever could help me answer this question. I am so... (1 Reply)
Discussion started by: Sparticus007
1 Replies
Login or Register to Ask a Question