Sponsored Content
Top Forums Shell Programming and Scripting Awk+colpos+negative if for 20 values Post 302909844 by Don Cragun on Sunday 20th of July 2014 06:49:58 PM
Old 07-20-2014
Quote:
Originally Posted by rajubollas
Hi All,

I am still waiting for other work around.
Please suggesst me
I have been trying off an on to figure out how your code works and have been unable to do so. I assume that this is the contents of $config_file_path/crt_extracts_branch_gswid_cntl:
Code:
##Files Structure on which position we do get Obligor/GSW ID for each file :
crt_extracts_branch_gsw_cntl file data
#################################################
#Carrs Extract File                                         GSWID Column Possition
#################################################
Grermany_Source_1.txt						3
Grermany_Source_2.txt						3
Grermany_Source_3.txt						6			
Grermany_Source_4.txt						1
Grermany_Source_5.txt						1
Grermany_Source_6.txt						4

So after running the commands in your script:
Code:
        set -A FILENAME   $( cat $config_file_path/crt_extracts_branch_gswid_cntl | grep -v "^#" | awk '{ print $1 }')
        set -A COLPOS     $( cat $config_file_path/crt_extracts_branch_gswid_cntl | grep -v "^#" | awk '{ print $4 }')
        set -A CTLCOLPOS  $( cat $config_file_path/crt_extracts_branch_gswid_cntl | grep -v "^#" | awk '{ print $3 }')

FILENAME is an array containing crt_extracts_branch_gsw_cntl and Grermany_Source_1.txt through Grermany_Source_6.txt, COLPOS is an array containing nothing, and CTLCOLPOS is an array containing the string data. Moving on from there nothing makes any sense to me. It would seem that you would be better off running awk once to extract the three fields you want and read the output in a while loop instead of creating three arrays to be processed later.

I'm sorry, but if I can't understand how this code is working, I don't know how to make it work faster.

Obviously you could get rid of the three calls to cat and the three calls to grep in the above pipelines and just use:
Code:
        arrayname=($(awk '!/^#/{print $n}))

for various values of arrayname and n to speed up the code above, and you could change:
Code:
	SOURCE_DIR=$( echo "/tgrrappkg3/DataStage/CONSUMER_BI/datap5/WSLGER")

to the simpler and faster:
Code:
	SOURCE_DIR="/tgrrappkg3/DataStage/CONSUMER_BI/datap5/WSLGER"

but these things are only done once; so they won't have a big effect on the speed of the inner loop.

So, since your code is working for you as is, I don't think I can help much.

You have lots of command substitutions that could be replaced by simple (and faster) parameter expansions. You have a command construction segment and an eval that seem like they could be replaced with a simple command invocation. But I hesitate to make any suggestions here because I can't figure out what is going on with the data you've shown us.

We might have a better chance of understanding what you were doing if you would show us the actual contents of the files named in your script and label those files with their names (as used in your script). AND, please use CODE tags for you sample input files so we can see what is actually in the files versus what may just be descriptive text before or after the contents of those files.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in adding positive & negative values in a column

Hi Gurus, In my file I have an amount field from position 74 to 87, which contains values starting with '+' as well as '-'. I want to add all positive values in a varible called "CREDIT" and all negative values in a variable "DEBIT". I know, we can use grep to identify values with positive and... (4 Replies)
Discussion started by: berlin_germany
4 Replies

2. Shell Programming and Scripting

printf in bash shell not printing negative values

hi i am using printf in a script and it is not printing negative values..i have to use printf to get rid of the newline..here is my code: fin=`echo $a - $b | bc` printf "${fin}," >> test these statements are in a loop. here is what i get when i try to subtract 4 from 8: ./scr1: line... (2 Replies)
Discussion started by: npatwardhan
2 Replies

3. Shell Programming and Scripting

Sorting positive and negative values

Hello, I have a list like this : 1 2 -4 0 -3 -7 5 6 etc. Is there a way to remove all the positive values and print only the negative values, without using grep, sed or awk? Thanks, Prasanna (4 Replies)
Discussion started by: prasanna1157
4 Replies

4. Shell Programming and Scripting

Find Where Values Change From Positive To Negative and viceversa

Hi all, I have a file that looks like shown below. I want to find places where the value in column 2 change from negative to positive and vice versa and return the value on column 1 at that point. I wonder if this is possible in shell script or awk .. please help! Here is the original data ... (6 Replies)
Discussion started by: malandisa
6 Replies

5. UNIX for Dummies Questions & Answers

Snmp Disk Problem = Negative Values

Ok, so i monitor disk space on remote machines using snmp. Works great for me. But whenever a particular partition happens to have Terabytes of data, snmp starts reporting negative values. Can someone please tell me how to get around this problem? The AllocationUnit is 512 bytes. Weird... (0 Replies)
Discussion started by: SkySmart
0 Replies

6. Shell Programming and Scripting

error- multiplying negative decimal values

a=10.02 pattern=-11.01 b=$(echo | awk '{ print $a*$pattern}') echo $b its not working even ALso tried `expr $a \* $pattern` No LUCK (3 Replies)
Discussion started by: saluja.deepak
3 Replies

7. Shell Programming and Scripting

replacing negative values in a column with zero

Hi, i need help on replacing negative values in a column with 0. any quick fix on this? thanks much. for instance, input: 1 2.3 -0.4 -25 12 13 45 -12 desired output 1 2.3 0 0 12 13 45 (4 Replies)
Discussion started by: ida1215
4 Replies

8. Shell Programming and Scripting

Conavert negative values to Zeros

Can anyone please assist me? Please find the attached input and output file for ur reference. a)Incase if i get negative value (ex:-000100) in the 11th column then i have to convert the value to 0000000(7 zeros-length is 7) and then print the entire record. b)Incase if there is no... (2 Replies)
Discussion started by: vinus
2 Replies

9. Shell Programming and Scripting

How to sum the value with negative values?

Hi Gurus, I have requirement need to sum the value, the logic is if the value is negative then time -1, I tried below two ways. one is failed, another one doesn't work. awk -F"," '{if($8< 0 $8*-1 else $8) sum+=$8}{print sum, $8} END{printf("%.2f\n",sum)}' awk -F","... (4 Replies)
Discussion started by: ken6503
4 Replies
All times are GMT -4. The time now is 06:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy