Sponsored Content
Full Discussion: Optimizing the code
Top Forums Shell Programming and Scripting Optimizing the code Post 302756685 by nua7 on Wednesday 16th of January 2013 10:02:48 AM
Old 01-16-2013
Optimizing the code

Hi,
I have two files in the format listed below. I need to find out all values from field 12 to field 20 present in file 2 and list them in file3(format as file2)

File1 :
Code:
FEIN,CHRISTA R|S00761779|057344138A|H2256|025||00000015ANLJ|DIAMOND|PROVIDER|C|20100125|V76.51|211.3|V12.72|||||||6240|20110128||20110128|N|6240|Supplies-MF POS|D|F|I
FEIN,CHRISTA R|S00761779|057344138A|H2256|027||00000015ANLJ|DIAMOND|PROVIDER|C|20100125|V76.51|211.3|V12.72|||||||6240|20110128||20110128|N|6240|Supplies-MF POS|D|F|I
CUMMINGS,JAMES J|S00634869|032488243A|H2256|015||00000015ANMT|DIAMOND|PROVIDER|C|20100115|574.10|745.5|271.3|564.1|346.90|314.01|311|V58.61|V12.54|6360|20110128||20110128|N|6360|Ther & Diag Injs-Drug-MF POS|D|F|I
DONOFRIO,DOMINIC J|S00746011|033363679A|H2256|024|MEMBER CHOSE A NEW PLAN WITHIN MEDICARE PREFERRED|00000018B5GB|DIAMOND|PROVIDER|C|20100118|562.10|455.0|V12.72|||||||6160|20110128||20110128|N|6160|Hospital Pharmacy-Drug-MF POS|D|F|I
DONOFRIO,DOMINIC J|S00746011|033363679A|H2256|025||00000018B5GB|DIAMOND|PROVIDER|C|20100118|562.10|455.0|V12.72|||||||6160|20110128||20110128|N|6160|Hospital Pharmacy-Drug-MF POS|D|F|I
DONOFRIO,DOMINIC J|S00746011|033363679A|H2256|027||00000018B5GB|DIAMOND|PROVIDER|C|20100118|562.10|455.0|V12.72|||||||6160|20110128||20110128|N|6160|Hospital Pharmacy-Drug-MF POS|D|F|I

File 2:
Code:
V26.4|ENC FOR FERT PRES COUNS
00|PROCEDURES AND INTERVENT
00.0|THERAPEUTIC ULTRASOUND
00.01|THERAPEUTIC ULTRASOUND
00.02|THERAPEUTIC ULTRASOUND
00.03|THERAPEUTIC ULTRASOUND
00.09|OTH THERAPEUTIC ULTRASOU
00.1|PHARMACEUTICALS
00.10|IMPL OF CHEMOTHERAPEUTIC
00.11|INF OF DROTRECOGIN ALFA
00.12|ADMIN OF INHALED NITRIC
00.13|INJ OR INF OF NESIRITIDE
00.14|INJ OR INF OF OXAOLIDINO
00.15|HIGH-DOSE INF INTERLEUKI
00.16|PRESSURIZED TREATMENT OF
00.17|INFUSION OF VASOPRESSOR
00.18|INF OF IMMUN ANTIBDY THP
00.19|DISRUPTION OF BLOOD BRAI
00.2|INTRAVASCULAR IMAGING
00.21|INTRAVASCULAR IMAGING OF
00.22|INTRAVASCULAR IMAGING OF

I have the following code which does the trick , but I was wondering if the code can be optimised in a single statement

Code:
awk -F '|' 'NR==FNR { a[$12]=$0; next  }a[$1] { print $0, a[$2] }' inst_full_denied mppartc.desc > test1
awk -F '|' 'NR==FNR { a[$13]=$0; next  }a[$1] { print $0, a[$2] }' inst_full_denied mppartc.desc >> test1
awk -F '|' 'NR==FNR { a[$14]=$0; next  }a[$1] { print $0, a[$2] }' inst_full_denied mppartc.desc >> test1
awk -F '|' 'NR==FNR { a[$15]=$0; next  }a[$1] { print $0, a[$2] }' inst_full_denied mppartc.desc >> test1
awk -F '|' 'NR==FNR { a[$16]=$0; next  }a[$1] { print $0, a[$2] }' inst_full_denied mppartc.desc >> test1
awk -F '|' 'NR==FNR { a[$17]=$0; next  }a[$1] { print $0, a[$2] }' inst_full_denied mppartc.desc >> test1
awk -F '|' 'NR==FNR { a[$18]=$0; next  }a[$1] { print $0, a[$2] }' inst_full_denied mppartc.desc >> test1
awk -F '|' 'NR==FNR { a[$19]=$0; next  }a[$1] { print $0, a[$2] }' inst_full_denied mppartc.desc >> test1
awk -F '|' 'NR==FNR { a[$20]=$0; next  }a[$1] { print $0, a[$2] }' inst_full_denied mppartc.desc >> test1

Any help will be appreciated!
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

Optimizing the system reliability

My product have around 10-15 programs/services running in the sun box, which together completes a task, sequentially. Several instances of the each program/service are running in the unix box, to manage the load and for risk-management reasons. As of now, we dont follow a strict strategy in... (2 Replies)
Discussion started by: Deepa
2 Replies

2. Filesystems, Disks and Memory

optimizing disk performance

I have some questions regarding disk perfomance, and what I can do to make it just a little (or much :)) more faster. From what I've heard the first partitions will be faster than the later ones because tracks at the outer edges of a hard drive platter simply moves faster. But I've also read in... (4 Replies)
Discussion started by: J.P
4 Replies

3. Shell Programming and Scripting

Optimizing for a Speed-up

How would one go about optimizing this current .sh program so it works at a more minimal time. Such as is there a better way to count what I need than what I have done or better way to match patterns in the file? Thanks, #declare variables to be used. help=-1 count=0 JanCount=0 FebCount=0... (3 Replies)
Discussion started by: switch
3 Replies

4. UNIX and Linux Applications

Optimizing query

Hi All, My first thread to this sub-forum and first thread of this sub-forum :) Here it is, Am trying to delete duplicates from a table retaining just 1 duplicate value out of the duplicate records for example : from n records of a table out of which x are duplicates, I want to remove x... (15 Replies)
Discussion started by: matrixmadhan
15 Replies

5. OS X (Apple)

Optimizing OSX

Hi forum, I'm administrating a workstation/server for my lab and I was wondering how to optimize OSX. I was wondering what unnecessary background tasks I could kick off the system so I free up as much memory and cpu power. Other optimization tips are also welcome (HD parameters, memory... (2 Replies)
Discussion started by: deiphon
2 Replies

6. Shell Programming and Scripting

Optimizing sed command

Hi, I would like to know if there is a command faster then sed, or a way to optimize my code... Here is the description of my problem: I have a file "file1" that is composed of 10 columns. The first one contain a list of ID, the second a list of number associated to the firs list of ID.... (1 Reply)
Discussion started by: jolecanard
1 Replies

7. Shell Programming and Scripting

Need help optimizing this piece of code (Shell script Busybox)

I am looking for suggestions on how I could possibly optimized that piece of code where most of the time is spend on this script. In a nutshell this is a script that creates an xml file(s) based on certain criteria that will be used by a movie jukebox. Example of data: $SORTEDTMP= it is a... (16 Replies)
Discussion started by: snappy46
16 Replies

8. Shell Programming and Scripting

Optimizing awk script

Can this awk statement be optimized? i ask because log.txt is a giant file with several hundred thousands of lines of records. myscript.sh: while read line do searchterm="${1}" datecurr=$(date +%s) file=$(awk 'BEGIN{split(ARGV,var,",");print var}' $line) ... (3 Replies)
Discussion started by: SkySmart
3 Replies

9. Shell Programming and Scripting

Optimizing bash script

any way the following code can be optimized? FIRSTIN=$( HKIPP=$(echo ${TMFR} | egrep -v "mo|MO|Mo" | egrep "m |M ") HRAMH=$(echo ${TMFR} | egrep "h|H") HRAMD=$(echo ${TMFR} | egrep "d|D") HRAMW=$(echo ${TMFR} | egrep "w|W") HKIPPO=$(echo ${TMFR} |... (5 Replies)
Discussion started by: SkySmart
5 Replies

10. Web Development

Optimizing JS and CSS

Yes. Got few suggestions. - How about minifying resources - mod_expires - Service workers setup https://www.unix.com/attachments/web-programming/7709d1550557731-sneak-preview-new-unix-com-usercp-vuejs-demo-screenshot-png (8 Replies)
Discussion started by: Akshay Hegde
8 Replies
merge(1)																  merge(1)

NAME
merge - three-way file merge SYNOPSIS
merge [-Llabel1 [-Llabel3]] [-p] [-q] file1 file2 file3 DESCRIPTION
merge incorporates all changes that lead from file2 to file3 into file1. The result goes to standard output if -p is present, into file1 otherwise. merge is useful for combining separate changes to an original. Suppose file2 is the original, and both file1 and file3 are modifications of file2. Then merge combines both changes. An overlap occurs if both file1 and file3 have changes in a common segment of lines. On a few older hosts where diff3 does not support the -E option, merge does not detect overlaps, and merely supplies the changed lines from file3. On most hosts, if overlaps occur, merge out- puts a message (unless the -q option is given), and includes both alternatives in the result. The alternatives are delimited as follows: <<<<<<< file1 lines in file1 ======= lines in file3 >>>>>>> file3 If there are overlaps, the user should edit the result and delete one of the alternatives. If the -L label1 and -L label3 options are given, the labels are output in place of the names file1 and file3 in overlap reports. DIAGNOSTICS
Exit status is 0 for no overlaps, 1 for some overlaps, 2 for trouble. IDENTIFICATION
Author: Walter F. Tichy. Revision Number: 1.1.6.2; Release Date: 1993/10/07. Copyright (C) 1982, 1988, 1989 by Walter F. Tichy. Copyright (C) 1990, 1991 by Paul Eggert. SEE ALSO
diff3(1), diff(1), rcsmerge(1), co(1) merge(1)
All times are GMT -4. The time now is 02:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy