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)						      General Commands Manual							  merge(1)

NAME
merge - three-way file merge SYNOPSIS
file1 file2 file3 DESCRIPTION
combines two files that are revisions of a single original file. The original file is file2, and the revised files are file1 and file3. identifies all changes that lead from file2 to file3 and from file2 to file1, then deposits the merged text into file1. If the option is used, the result goes to standard output instead of file1. An overlap occurs if both file1 and file3 have changes in the same place. prints how many overlaps occurred, and includes both alterna- tives in the result. The alternatives are delimited as follows: lines in file1 lines in file3 If there are overlaps, edit the result in file1 and delete one of the alternatives. This command is particularly useful for revision control, especially if file1 and file3 are the ends of two branches that have file2 as a common ancestor. EXAMPLES
A typical use for is as follows: 1. To merge an RCS branch into the trunk, first check out the three different versions from RCS (see co(1)) and rename them for their revision numbers: 5.2, 5.11, and 5.2.3.3. File 5.2.3.3 is the end of an RCS branch that split off the trunk at file 5.2. 2. For this example, assume file 5.11 is the latest version on the trunk, and is also a revision of the "original" file, 5.2. Merge the branch into the trunk with the command: 3. File 5.11 now contains all changes made on the branch and the trunk, and has markings in the file to show all overlapping changes. 4. Edit file 5.11 to correct the overlaps, then use the command to check the file back in (see ci(1)). WARNINGS
uses the ed(1) system editor. Therefore, the file size limits of ed(1) apply to AUTHOR
was developed by Walter F. Tichy. SEE ALSO
diff3(1), diff(1), rcsmerge(1), co(1). merge(1)
All times are GMT -4. The time now is 10:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy