Optimizing the code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Optimizing the code
# 1  
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!
# 2  
Old 01-16-2013
I am not sure if I understand what you are looking for, something like this?
Code:
awk -F\| 'NR==FNR{A[$1]=$0; next} {for(i=12; i<=20; i++) if($i in A)print A[$i]}' mppartc.desc inst_full_denied

If not what is your output file? Can it be that are no matches between the two sample files?
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 01-16-2013
Worked!!

Thanks! This helps! I wanted to find all the corresponding values of mppartc.desc for all the values from fields 12 to 20 in the mppartc.desc format.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
Login or Register to Ask a Question