Awk+colpos+negative if for 20 values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk+colpos+negative if for 20 values
# 1  
Old 07-07-2014
Awk+colpos+negative if for 20 values

Hi All,

i have 20 Obligors when ever i dont find all of them on particular row/line from each in put i need to print it in different file.

using below command but it is not working please help at earliest.

Steps:
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 }')

Code:
#Carrs Extract File                                             Column Position     Control File column position	GSWID Column Possition
##############################################################################################################################################
Assessment_Extract.txt                                       4                     0-17					3

Code:
$ cat GERMANY_Obligor_filter_ctl
##Obligor information file
##For new obligor for search contion add "|| $colpos != xxxxxx" in format
##make sure all condition values in single line
$colpos  != 228070 || $colpos  != 228071 || $colpos  != 228072 || $colpos  != 228073 || $colpos  != 228074 || $colpos  != 228075 || $colpos  != 228076 || $colpos  != 228077 || $colpos  != 228078 || $colpos  != 228079 || $colpos  != 228080 || $colpos  != 228081 || $colpos  != 228082 || $colpos  != 228083 || $colpos  != 228084 || $colpos  != 228085 || $colpos  != 228086 || $colpos  != 228196 || $colpos  != 228199$


ifcondition_val=$( grep -v "^#" $config_file_path/GERMANY_Obligor_filter_ctl)

command_construction=$( echo "cat \$SOURCE_DIR/\${FILENAME[\$x]}  | awk -F\"|\" -v colpos=\"\${COLPOS[\$x]}\"  'if (\"\$ifcondition_val\") { print \$0 }'  > \$NEWFILENAME")

eval $command_construction

please help me how to achieve it. i am trying to assign values dynamically. how to compare column position value in "if then else" dynamically?

Last edited by Scrutinizer; 07-07-2014 at 04:35 PM.. Reason: CODE tags
# 2  
Old 07-07-2014
Can you please provide sample input and output and re-state your problem a bit clearer if it is possible.
# 3  
Old 07-07-2014
I see several things that are likely to fail, but I don't understand what you're trying to do so I don't know how to fix them. Here are a few things for you to consider:
  1. Shell variables are not expanded inside single quoted strings.
  2. Inside awk programs, awk variables don't need a $ unless you are trying to get data from the field in the current input line specified by the value that variable expands to.
  3. Anytime you have an expression starting with variable != value || variable != another_value, the evaluation of that expression is TRUE. Adding more || expression sequences to that expression will never change its value to FALSE.
  4. If an input line that you are processing with awk or grep is longer than LINE_MAX bytes, the results are undefined. You can get the value of LINE_MAX for your system by running the command: getconf LINE_MAX. If colpos != 228070 means that your input lines are 228,070 bytes or more in length, you will not be able to use awk or grep to process those files on some systems.
# 4  
Old 07-09-2014
Hi Don,

Thanks for looking into my requirement let me summerize what i am trying achieve.

i have source data in Germany_Source_1.txt, Germany_Source_2.txt ...nth.txt files which contains business keys.
Obligor_ID is business key. using given 18 Obligor_ID i am dividing Germay_Source files for Greece and Germany when Given Obligor_ID not found in each row then i need that row/line as Greece_Source_1.txt .*_2.txt....*_nth.txt file found Obligor_ID information i am keeping Greece_Source_1 ...*_2.txt....*_nth.txt.
Note: Obligor_ID column position is not a fixed position on every file

i would like to achieve based on source file i have to check Obligor_ID coulm position on the column then i have to write out put to another file whenever list of 19 Obligors not found on the row/line.

Source Data sample
Code:
$ Grermany_Source_1.txt file data
1|ACTIVE|FINANCIAL_RI|3456-89-12|456789|RTNG_DLR|RI_FIN_STMT|234
67|ACTIVE|FINANCIAL_RI|9012-45-78|012345|RTNG_DLR|RI_FIN_STMT|890
2|ACTIVE|FINANCIAL_RI|4567-90-23|567890|RTNG_DLR|RI_FIN_STMT|345
78|ACTIVE|FINANCIAL_RI|0123-56-89|123456|RTNG_DLR|RI_FIN_STMT|901
3|ACTIVE|FINANCIAL_RI|5678-01-34|678901|RTNG_DLR|RI_FIN_STMT|456
89|ACTIVE|FINANCIAL_RI|1234-67-90|234567|RTNG_DLR|RI_FIN_STMT|012
4|ACTIVE|FINANCIAL_RI|6789-12-45|789012|RTNG_DLR|RI_FIN_STMT|567
9|ACTIVE|FINANCIAL_RI|1234-67-90|234567|RTNG_DLR|RI_FIN_STMT|012
45|ACTIVE|FINANCIAL_RI|7890-23-56|890123|RTNG_DLR|RI_FIN_STMT|678
01|ACTIVE|FINANCIAL_RI|3456-89-12|456789|RTNG_DLR|RI_FIN_STMT|234
6|ACTIVE|FINANCIAL_RI|8901-34-67|901234|RTNG_DLR|RI_FIN_STMT|789
1|ACTIVE|FINANCIAL_RI|3456-89-12|456789|RTNG_DLR|RI_FIN_STMT|234
6|ACTIVE|FINANCIAL_RI|8901-34-67|901234|RTNG_DLR|RI_FIN_STMT|789
1|ACTIVE|FINANCIAL_RI|3456-89-12|456789|RTNG_DLR|RI_FIN_STMT|234
67|ACTIVE|FINANCIAL_RI|9012-45-78|012345|RTNG_DLR|RI_FIN_STMT|890
23|ACTIVE|FINANCIAL_RI|5678-01-34|678901|RTNG_DLR|RI_FIN_STMT|456
8|ACTIVE|FINANCIAL_RI|0123-56-89|123456|RTNG_DLR|RI_FIN_STMT|901
3|ACTIVE|FINANCIAL_RI|5678-01-34|678901|RTNG_DLR|RI_FIN_STMT|456
8|ACTIVE|FINANCIAL_RI|0123-56-89|123456|RTNG_DLR|RI_FIN_STMT|901
34|ACTIVE|FINANCIAL_RI|6789-12-45|789012|RTNG_DLR|RI_FIN_STMT|567
9|ACTIVE|FINANCIAL_RI|1234-67-90|234567|RTNG_DLR|RI_FIN_STMT|012
4|ACTIVE|FINANCIAL_RI|6789-12-45|789012|RTNG_DLR|RI_FIN_STMT|567
9|ACTIVE|FINANCIAL_RI|1234-67-90|234567|RTNG_DLR|RI_FIN_STMT|012

Code:
$$Obligor Test filter file
GERMANY_Obligor_filter_ctl file data

Code:
##Obligor information file
##For new obligor for search contion add "&& $colpos !=xxxxxx" in format
##make sure all condition values in single line
$colpos != 228070 && $colpos != 228071 && $colpos != 228072 && $colpos != 228073 && $colpos != 228074 && $colpos != 228075 && $colpos != 228076 && $colpos != 228077 && $colpos != 228078 && $colpos != 228079 && $colpos != 228080 && $colpos != 228081 && $colpos != 228082 && $colpos != 228083 && $colpos != 228084 && $colpos != 228085 && $colpos != 228086 && $colpos != 228196 && $colpos != 228299

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


Code:
Script Part:

if [[ -f $config_file_path/crt_extracts_branch_gswid_cntl ]]
then
        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 }')

	SOURCE_DIR=$( echo "/tgrrappkg3/DataStage/CONSUMER_BI/datap5/WSLGER")
	x=0
        while (( $x <  ${#FILENAME[*]}  ))
        do
                if [[ -f $SOURCE_DIR/${FILENAME[$x]} ]]
                then
                        MSG="Processing file $SOURCE_DIR/${FILENAME[$x]}:INFO"
                        echo $MSG;

                        ##DISTINCT_BRNCH_NBRS=$( cat $SOURCE_DIR/${FILENAME[$x]} | awk -F"|" -v colpos="${COLPOS[$x]}" '{ print $colpos }' | sort -u )
			##DISTINCT_OBLIGOR_NBRS=$( cat $config_file_path/Greece_Obligor_filter.txt	| grep -v "^#"| awk '{ print $1 }' | sort -u )

                        ##for OBLIGOR_NBRS in $( echo $DISTINCT_OBLIGOR_NBRS )
                        ##do
                                ##MSG="Processing branch $OBLIGOR_NBRS:$INFO"
                                ##echo $MSG;
                                PART1FILENAME=$( echo ${FILENAME[$x]} | awk -F"." '{ print $1 }')
                                PART2FILENAME=$( echo ${FILENAME[$x]} | awk -F"." '{ print $2 }')
                                NEWFILENAME=$( echo "$SOURCE_DIR/GERMANY_$PART1FILENAME.$PART2FILENAME")
				touch $NEWFILENAME
                                ##cat $SOURCE_DIR/${FILENAME[$x]}                                                                |
                                ##awk -F"|" -v colpos="${COLPOS[$x]}" -v obligor_nbr="${OBLIGOR_NBRS}" '
                                ##          ( $colpos==obligor_nbr ) { print $0 }'                                          > $NEWFILENAME
				##Reading GERMANY_Obligor_filter_ctl file
				##set -x
				if [[ -f $config_file_path/GERMANY_Obligor_filter_ctl ]]
				then 
					##this an if then else condition values for command_construction variable
					ifcondition_val=$( grep -v "^#" $config_file_path/GERMANY_Obligor_filter_ctl)
					command_construction=$( echo "cat $SOURCE_DIR/${FILENAME[$x]}  | awk -F\"|\" -v colpos=\"${COLPOS[$x]}\"  '{if ("$ifcondition_val") { print \$0 }}'  > $NEWFILENAME")
					##Executing cunstructed command with EVAL command
					eval $command_construction
                                	RC=$?
                                	if [[ $RC -ne 0 ]]
                                	then
                                        MSG="Error in creating file $NEWFILENAME:ALERT"
                                        echo $MSG;
                                        return -1
                                	else

                                        MSG="$NEWFILENAME file created:INFO"
                                        echo $MSG;
                                	fi
				fi
				##set +x
                         ##done
			MSG="Completed processing file ${FILENAME[$x]}"
                        echo $MSG;
                else
                        MSG="File not found $SOURCE_DIR/${FILENAME[$x]}.     Proceeding to next file:WARN"
                        echo $MSG;
                fi
                x=$(echo "$x+1" | bc)
        done
else

###

I have corrected command_construction variable properly, now my script is working fine. but i am still looking for better solution on below part of script to maintain it easily.

Can you please suggest with good solution in below part of script how maintain it easy.
Code:
					##this an if then else condition values for command_construction variable
					ifcondition_val=$( grep -v "^#" $config_file_path/GERMANY_Obligor_filter_ctl)
					command_construction=$( echo "cat $SOURCE_DIR/${FILENAME[$x]}  | awk -F\"|\" -v colpos=\"${COLPOS[$x]}\"  '{if ("$ifcondition_val") { print \$0 }}'  > $NEWFILENAME")
					##Executing cunstructed command with EVAL command
					eval $command_construction

Moderator's Comments:
Mod Comment Please use CODE tags for sample input and output as well as for code segments.

Last edited by Corona688; 09-08-2016 at 12:24 PM.. Reason: Replaced private data with gibberish
# 5  
Old 07-15-2014
Hi All,

I am still waiting for other work around.
Please suggesst me
# 6  
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.
# 7  
Old 07-21-2014
Thanks Don, i will take your inputs for faster and simple scripts going forward.
Please find here my actual code.

Code:
#!/bin/ksh


#########################################################################
# Date:	25 June 2014							#
# Author : Raju Bolla							# 
# Email: raju.bolla@hp.com						#
# This script will Segregate data from CARRs Germany source files	#
# Germany Files For data load activities				#
# 									#
# Sustain will execute this Script as a last pre-load activty step	#
#									#
#########################################################################



#Function to check the return code of the command executed
chckRC()
	{
		if [ $1 -ne 0 ]
		then
				echo "$2" >/dev/null
				exit 1
		fi	
	}

##Copy Germany Files to GERMANY Folder
##Copy Germany Files to Greece Folder
#Bkp Path Germany Path
SOURCE_COMMON=$( echo "/pgrrappkg3/DataStage/CONSUMER_BI/datap5/WSLGER_WSLGREECE")
TARGET_GREECE=$( echo "/pgrrappkg3/DataStage/CONSUMER_BI/datap5/WSLGER") 
cd $SOURCE_COMMON
cp Crs_*Extract.txt $TARGET_GREECE/
cp Crs_*CTL.txt $TARGET_GREECE/
RC=$?
chckRC $RC "Aborted while executing Copy Germany Files to Greece Folder Part"
echo "Completed the execution of Copy Germany Files to Greece Folder Part" >/dev/null

cd $TARGET_GREECE
config_file_path=$( echo "/pgrrappkg3/DataStage/CONSUMER_BI/etlisp5/cfg")
if [[ -f $config_file_path/crt_extracts_branch_gswid_cntl ]]
then
        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 }')

	SOURCE_DIR=$( echo "/pgrrappkg3/DataStage/CONSUMER_BI/datap5/WSLGER")
	x=0
        while (( $x <  ${#FILENAME[*]}  ))
        do
                if [[ -f $SOURCE_DIR/${FILENAME[$x]} ]]
                then
                        MSG="Processing file $SOURCE_DIR/${FILENAME[$x]}:INFO"
                        echo $MSG;

                                PART1FILENAME=$( echo ${FILENAME[$x]} | awk -F"." '{ print $1 }')
                                PART2FILENAME=$( echo ${FILENAME[$x]} | awk -F"." '{ print $2 }')
                                NEWFILENAME=$( echo "$SOURCE_DIR/GERMANY_$PART1FILENAME.$PART2FILENAME")
				touch $NEWFILENAME
				##Reading GERMANY_Obligor_filter_ctl file
				##set -x
				if [[ -f $config_file_path/GERMANY_Obligor_filter_ctl ]]
				then 
					##this an if then else condition values for command_construction variable
					ifcondition_val=$( grep -v "^#" $config_file_path/GERMANY_Obligor_filter_ctl)
					command_construction=$( echo "cat $SOURCE_DIR/${FILENAME[$x]}  | awk -F\"|\" -v colpos=\"${COLPOS[$x]}\"  '{if ("$ifcondition_val") { print \$0 }}'  > $NEWFILENAME")
					##Executing cunstructed command with EVAL command
					eval $command_construction
                                	RC=$?
                                	if [[ $RC -ne 0 ]]
                                	then
                                        MSG="Error in creating file $NEWFILENAME:ALERT"
                                        echo $MSG;
                                        return -1
                                	else

                                        MSG="$NEWFILENAME file created:INFO"
                                        echo $MSG;
                                	fi
				fi
				##set +x

				##CTL File generation
				for CTL in $( echo ${CTLCOLPOS[$x]} | awk '{ FldCnt=split($0,Arr,"-"); print FldCnt }' )
				do
					CTLCTR=1
					DISPLAYVAL=""
					while (( $CTLCTR <= $CTL ))
					do
						VAL=$( echo ${CTLCOLPOS[$x]} | awk -v ctr="${CTLCTR}" '{ FldCnt=split($0,Arr,"-"); print Arr[ctr] }')
						if [[ $VAL = 0 ]];
						then
						    ROWCNT=$(cat $NEWFILENAME | wc -l ) 
						    DISPLAYVAL="$DISPLAYVAL""$ROWCNT|"
						else
						    SUMVAL=$(cat $NEWFILENAME | awk -F"|" -v val="${VAL}" ' 
										BEGIN { tot=0 } {tot=tot+$val } END { printf "%.2f",tot }')
						    DISPLAYVAL="$DISPLAYVAL""$SUMVAL|"
						fi
						CTLCTR=$(echo "$CTLCTR+1" | bc)
					done
					CTLNEWFILENAME=$( echo $NEWFILENAME 	| sed s/Extract/CTL/g )
					CTLORGFILENAME=$( echo ${FILENAME[$x]}	| sed s/Extract/CTL/g )
					if [[ -f $SOURCE_DIR/$CTLORGFILENAME ]]
					then
						cat $SOURCE_DIR/$CTLORGFILENAME | head -1  	> $CTLNEWFILENAME
					else
						echo "No header for CTL file found" 		> $CTLNEWFILENAME
						MSG="$CTLORGFILENAME file not found :WARN" 
						echo $MSG;
					fi		
					echo $DISPLAYVAL | sed s/\|$//g				>> $CTLNEWFILENAME
				done
                        MSG="Completed processing file ${FILENAME[$x]}"
                        echo $MSG;
                else
                        MSG="File not found $SOURCE_DIR/${FILENAME[$x]}. Proceeding to next file:WARN"
                        echo $MSG;
                fi
                x=$(echo "$x+1" | bc)
        done
else
  MSG="Invalid file $config_file_path/crt_extracts_branch_gswid_cntl:ALERT"
  echo $MSG;
fi;
## End of Generating Greece and Germany Files GREECE_* and Names

##Modifying Germany Data with Greece data and writing to Sed_*GREE
##Greece Files Path
cd $SOURCE_DIR
##Renaming file to Atcual name
for o in `ls -1 GERMANY_Crs_*_Extract.txt`
do
Actual_FILE_Name=`echo "$o" | sed -e 's/GERMANY\_//'`; ##Indetifying Extract File Name
mv $o $Actual_FILE_Name
RC=$?
chckRC $RC "Aborted while executing Renaming file to Atcual name Part"
echo "Completed the execution of Renaming file to Atcual name Part" >/dev/null
done;

##Renaming file to Atcual name
for p in `ls -1 GERMANY_Crs_*_CTL.txt`
do
Actual_FILE_Name=$( echo "$p" | sed -e 's/GERMANY\_//'); ##Indetifying Extract File Name
mv $p $Actual_FILE_Name
RC=$?
chckRC $RC "Aborted while executing Renaming file to Atcual name Part"
echo "Completed the execution of Renaming file to Atcual name Part" >/dev/null
done;
##set +x
###End of Script

Please find control files data.
Code:
cat GERMANY_Obligor_filter_ctl
##Obligor information file
##For new obligor for search contion add "&& $colpos !=xxxxxx" in format
##make sure all condition values in single line
$colpos != 228070 && $colpos != 228071 && $colpos != 228072 && $colpos != 228073 && $colpos != 228074 && $colpos != 228075 && $colpos != 228076 && $colpos != 228077 && $colpos != 228078 && $colpos != 228079 && $colpos != 228080 && $colpos != 228081 && $colpos != 228082 && $colpos != 228083 && $colpos != 228084 && $colpos != 228085 && $colpos != 228086 && $colpos != 228196 && $colpos != 228299

cat crt_extracts_branch_gsw_cntl

################################################################################
#
#  carrs_extracts_branch_gswid_cntl
#
################################################################################
#
# carrs_extracts_branch_cntl is a control file containing carrs extract file names
# and column position of Branch nbr in that extract file
#
################################################################################
#
# Column Definition:
# 1st Column     Carrs Extract file name
# 2nd Column     Colump position of "Branch Number"
# 4th Column     Colump position of "GSW ID or Obligor ID"
##############################################################################################################################################
#Carrs Extract File                                             Column Position     Control File column position	GSWID Column Possition
##############################################################################################################################################
Crs_Assessment_Extract.txt                                       4                     0-17					3
Crs_Involved_Party_Risk_Rating_Extract.txt                       4                        0					3
Crs_Model_Input_Extract.txt                                      7                     0-12					6			
Crs_Involved_Party_Watchlist_Extract.txt                         2                        0					1
Crs_Involved_Party_Default_Extract.txt                           2			0-9					1
Crs_AR_X_IP_Extract.txt                                          3                        0					4
Crs_Oprtnl_Risk_Assessment_Extract.txt                           4                        0					3
Crs_Financial_Resource_Item_Extract.txt                         11                      0-5					8
#Crs_County_Extract.txt                                           5                        0
#Crs_State_Extract.txt                                            4                        0
#Crs_City_Extract.txt                                             6                        0
Crs_Involved_Party_Involved_Party_Extract.txt                    6                        0					1
Crs_Customer_Obligor_Extract.txt                                 6                        0					15	
#Crs_Post_Addr_Extract.txt                                       13                        0
Crs_Involved_Party_Post_Address_Extract.txt	                 23                       0					3
#Crs_IP_Product_Plan_Grp_Rating_Extract.txt                       8                        0					1
Crs_Financial_Resource_Item_Hdr_Extract.txt                      8                        0					5
Crs_IP_Credit_Facility_Rating_Extract.txt                        2                     0-10					1
Crs_Txn_Ev_Dlr_Charges_Extract.txt                               1                     0-10					2

Please provide your suggestion on above code
Code:
command_construction=$( echo "cat $SOURCE_DIR/${FILENAME[$x]}  | awk -F\"|\" -v colpos=\"${COLPOS[$x]}\"  '{if ("$ifcondition_val") { print \$0 }}'  > $NEWFILENAME")

especially here i am looking for a refine my script and simple use of
Code:
cat GERMANY_Obligor_filter_ctl

file
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

Featured Tech Videos