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

NAME
join - relational database operator SYNOPSIS
join [ options ] file1 file2 DESCRIPTION
Join forms, on the standard output, a join of the two relations specified by the lines of file1 and file2. If file1 is `-', the standard input is used. File1 and file2 must be sorted in increasing ASCII collating sequence on the fields on which they are to be joined, normally the first in each line. There is one line in the output for each pair of lines in file1 and file2 that have identical join fields. The output line normally con- sists of the common field, then the rest of the line from file1, then the rest of the line from file2. Fields are normally separated by blank, tab or newline. In this case, multiple separators count as one, and leading separators are dis- carded. These options are recognized: -an In addition to the normal output, produce a line for each unpairable line in file n, where n is 1 or 2. -e s Replace empty output fields by string s. -jn m Join on the mth field of file n. If n is missing, use the mth field in each file. -o list Each output line comprises the fields specified in list, each element of which has the form n.m, where n is a file number and m is a field number. -tc Use character c as a separator (tab character). Every appearance of c in a line is significant. SEE ALSO
sort(1), comm(1), awk(1) BUGS
With default field separation, the collating sequence is that of sort -b; with -t, the sequence is that of a plain sort. The conventions of join, sort, comm, uniq, look and awk(1) are wildly incongruous. 7th Edition April 29, 1985 JOIN(1)
All times are GMT -4. The time now is 07:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy