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

NAME
lam -- laminate files SYNOPSIS
lam [-f min.max] [-s sepstring] [-t c] file ... lam [-p min.max] [-s sepstring] [-t c] file ... DESCRIPTION
The lam utility copies the named files side by side onto the standard output. The n-th input lines from the input files are considered frag- ments of the single long n-th output line into which they are assembled. The name `-' means the standard input, and may be repeated. Normally, each option affects only the file after it. If the option letter is capitalized it affects all subsequent files until it appears again uncapitalized. The options are described below: -f min.max Print line fragments according to the format string min.max, where min is the minimum field width and max the maximum field width. If min begins with a zero, zeros will be added to make up the field width, and if it begins with a `-', the fragment will be left- adjusted within the field. -p min.max Like -f, but pad this file's field when end-of-file is reached and other files are still active. -s sepstring Print sepstring before printing line fragments from the next file. This option may appear after the last file. -t c The input line terminator is c instead of a newline. The newline normally appended to each output line is omitted. To print files simultaneously for easy viewing use pr(1). EXAMPLES
The command lam file1 file2 file3 file4 joins 4 files together along each line. To merge the lines from four different files use lam file1 -S " " file2 file3 file4 Every 2 lines of a file may be joined on one line with lam - - < file and a form letter with substitutions keyed by `@' can be done with lam -t @ letter changes AUTHOR
John A. Kunze <jak@ucop.edu> SEE ALSO
join(1), paste(1), pr(1), printf(3) STANDARDS
Some of the functionality of lam is standardized as the paste(1) utility by IEEE Std 1003.2 (``POSIX.2''). BSD
September 20, 2001 BSD
All times are GMT -4. The time now is 08:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy