Sponsored Content
Full Discussion: Validate numerical
Top Forums UNIX for Dummies Questions & Answers Validate numerical Post 302925967 by tricampeon81 on Thursday 20th of November 2014 12:34:44 PM
Old 11-20-2014
add before I need to validate that either number as I can make
it is in this if


* if (substr ($ 0,1,1) == 'D' && substr ($ 0,24,1) == "C") # Full details Feed

Code:
BEGIN { 
	   #VARIABLES PARA CARGOS
	   #Awk ancargado de validar el detaale de un archivo cnotra la caberera 
	    cat=0;
		contador =0;
		cantidad_de_registros=0;
	    total_cabecera_abono=0;
		total_cabecera_cargo=0;
		
		suma_total_cargos=0;
		suma_total_abono=0;	

		
		ok_cantidad=0;
		nok_cantidad=1;
		
		ok_abono=0;
		ok_cargo=0;
		
		nok_cargo=1;
		nok_abono=1;
		valor=0;
		valor_final=0;
		ban=0;
		
	 }	
	 { #recorro archivo
	 
	 #datos de cabecera cantidad de registro
	 if (substr($0,1,1) =="C" && cat == 0)#Cantidad de registros cabecera
	  {
	   cantidad_de_registros=int(substr($0,2,8))
	  }
	  #rescato los cargos
	  if (substr($0,1,1) =="C" && cat == 0)#total cargo cabecera
	  {
	   total_cabecera_cargo=int(substr($0,24,14))
	  }
	  
	  #Datos de cabecera
	  if (substr($0,1,1) =="C" && cat == 0)#total abono cabecera
	  {
	   total_cabecera_abono=int(substr($0,10,14))
	  }
	  
	  #Datos de Detalle
	    if (substr($0,1,1) =="D" && substr($0,24,1)	=="D") #total Cargos detalles
	    {
		   suma_total_cargos=suma_total_cargos+int(substr($0,26,10))
		   contador =  contador+1;
		  valor =  int(substr($0,26,10))
	    }			
	  
        if (substr($0,1,1) =="D" && substr($0,24,1) =="C")#total Abono detalle
	    {
		 suma_total_abono=suma_total_abono+int(substr($0,26,10))
		 contador =  contador+1;
		 valor =  int(substr($0,26,10))
		 #aca tengo que validar que sea numerico
		 valor_salida=`echo $valor | grep "^[1234567890]*$"`
	    }			  
	    cat=1;
	}
END{
    if (total_cabecera_cargo == suma_total_cargos )
	{
	 #printf(" Son iguales los cargos \n")
	 #printf("Total cabecera cargos:[%s] \n",total_cabecera_cargo)
	 #printf(" Total deatalle cargos:[%s] \n",suma_total_cargos)	
	 printf("%s",ok_cargo)	
	}
	else
	{
	 #printf("\n Son distintos los cargos \n")
	 #printf("Total cabecera cargos:[%s] \n",total_cabecera_cargo)
	 #printf("Total deatalle cargos:[%s] \n",suma_total_cargos)		 
	 printf("%s",nok_cargo)	
 	}	 
	if (total_cabecera_abono == suma_total_abono)
	{
	 #printf("Son iguales los abonos \n")
	 #printf("Total cabecera abonos \n:[%s]\n",total_cabecera_abono)
	 #printf("Total detalle abonos \n:[%s]\n",suma_total_abono)
	 printf("%s",ok_abono)
	}
	else
	{
	 #printf("\n Son distintos los abonos \n")
	 #printf("Total cabecera abonos:[%s] \n",total_cabecera_abono)
	 #printf("Total detalle abonos:[%s] \n",suma_total_abono)
	 printf("%s",nok_abono)
	}	 
	
	if (contador == cantidad_de_registros)
	{
	  #printf("cantidad de Registros ok \n")
	  printf("%s",ok_cantidad)
	}
	else
	{
	  #printf("\n cantidad de registros cabecera:{%s}\n",cantidad_de_registros)
	  #printf("cantidad de registros detalle:{%s}\n",contador)
	  printf("%s",nok_cantidad)
	}	 
	
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Numerical Decision

I'm tryning to do something like this, I have this file: spaces12tabgoodbye spaces3tabhello I want to copy to another file the lines that have the number above 10... I thought using sort -rn but I don't know how to discard the lines that have the number below 10. Any idea? Thanks (3 Replies)
Discussion started by: pmpx
3 Replies

2. Shell Programming and Scripting

ksh numerical RegX

I need to distinguish between numerical characters in a script: echo "Enter a number." read num if (( $num = * )) ; then exit 0 fi this RegX does not work. Any suggestions? (5 Replies)
Discussion started by: prkfriryce
5 Replies

3. UNIX for Dummies Questions & Answers

how to get the value of a numerical expression

Hi, All, I want to calculate a specific value of a Gaussian distribution, say the mean is a=3, variance is b=5, the indepentent variable is x=2, how could I get the y which is the Gaussian distribution value of x. Thanks, Jenny (1 Reply)
Discussion started by: Jenny.palmy
1 Replies

4. UNIX for Dummies Questions & Answers

Can grep do numerical comparisons?

Say for example I have a list of numbers.. 5 10 13 48 1 could I use grep to show only those numbers that are above 10? For various reasons I can only use grep... not awk or sed etc. (7 Replies)
Discussion started by: Uss_Defiant
7 Replies

5. Shell Programming and Scripting

variable numerical test

Hi I have a variable which should be any number between 1 and 50. It could also be any string/empty string. I have a code written below. The point is when the variable contains string. I don't want the code below to error out. Instead fall in the else bucket. && dothis_1 || dothis_2 (1 Reply)
Discussion started by: tostay2003
1 Replies

6. Shell Programming and Scripting

COMM and Numerical Sorting

Hi, Hope someone can shed some light on this... I have two lists of numbers I am comparing using COMM. If the first list is empty, and I sort both lists like so: DIFF=`comm -3 <(echo "$EMPTY" | sort -n) <(echo "$NUMBERS" | sort -n)`I get the error: comm: file 2 is not in sorted order But... (2 Replies)
Discussion started by: LostInTheWoods
2 Replies

7. UNIX for Dummies Questions & Answers

Numerical Labeling using sed

Hi, I have been working on this problem, but could only get so far. I have a file that looks like this (cat,chimp,(((dog,cat,cow),orangutan),((horse,((cat,dog),(cow,pig))),cat,mouse,rat))); I would like after each instance of the word 'cat' to have an incrementing numerical label. I... (5 Replies)
Discussion started by: cavanac2
5 Replies

8. UNIX for Dummies Questions & Answers

List files according to the numerical value

Hi, I have a large number of files which are named as follows. VF_50, VF_100, VF_150, VF_250, VF_300, VF_350, VF_400, VF_450, VF_500. When I do an 'ls' it arranges the files in the following way VF_100, VF_150, VF_250, VF_300, VF_350, VF_400, VF_450, VF_50, VF_500. Is there a way to... (2 Replies)
Discussion started by: lost.identity
2 Replies

9. UNIX for Dummies Questions & Answers

How to use grep with numerical values?

I'm new to Unix and I have been trying to fix this problem for the past week. How would I use grep to display only certain numbers for a list. For example, if I have this list: Joe senior 4/50 John junior 25/50 Mary junior 41/50 Martha sophomore 2/50 ...How do I get a file... (1 Reply)
Discussion started by: PTcharger
1 Replies

10. Shell Programming and Scripting

Script regarding non numerical or empty value

Hello Team, I need bash script to check if my output is non numerical or empty. if its then my output should display default value as 0 basically, I am reading value from txt file. most of numerical value, in case there is no numerical value or its empty, then my output should be 0. ... (5 Replies)
Discussion started by: ghpradeep
5 Replies
SUBSTR(3)								 1								 SUBSTR(3)

substr - Return part of a string

SYNOPSIS
string substr (string $string, int $start, [int $length]) DESCRIPTION
Returns the portion of $string specified by the $start and $length parameters. PARAMETERS
o $string - The input string. Must be one character or longer. o $start - If $start is non-negative, the returned string will start at the $start'th position in $string, counting from zero. For instance, in the string ' abcdef', the character at position 0 is ' a', the character at position 2 is ' c', and so forth. If $start is negative, the returned string will start at the $start'th character from the end of $string. If $string is less than or equal to $start characters long, FALSE will be returned. Example #1 Using a negative $start <?php $rest = substr("abcdef", -1); // returns "f" $rest = substr("abcdef", -2); // returns "ef" $rest = substr("abcdef", -3, 1); // returns "d" ?> o $length - If $length is given and is positive, the string returned will contain at most $length characters beginning from $start (depend- ing on the length of $string). If $length is given and is negative, then that many characters will be omitted from the end of $string (after the start position has been calculated when a $start is negative). If $start denotes the position of this trunca- tion or beyond, false will be returned. If $length is given and is 0, FALSE or NULL, an empty string will be returned. If $length is omitted, the substring starting from $start until the end of the string will be returned. Example #2 Using a negative $length <?php $rest = substr("abcdef", 0, -1); // returns "abcde" $rest = substr("abcdef", 2, -1); // returns "cde" $rest = substr("abcdef", 4, -4); // returns false $rest = substr("abcdef", -3, -1); // returns "de" ?> RETURN VALUES
Returns the extracted part of $string; or FALSE on failure, or an empty string. CHANGELOG
+--------------+---------------------------------------------------+ | Version | | | | | | | Description | | | | +--------------+---------------------------------------------------+ |5.2.2 - 5.2.6 | | | | | | | If the $start parameter indicates the position | | | of a negative truncation or beyond, false is | | | returned. Other versions get the string from | | | start. | | | | +--------------+---------------------------------------------------+ EXAMPLES
Example #3 Basic substr(3) usage <?php echo substr('abcdef', 1); // bcdef echo substr('abcdef', 1, 3); // bcd echo substr('abcdef', 0, 4); // abcd echo substr('abcdef', 0, 8); // abcdef echo substr('abcdef', -1, 1); // f // Accessing single characters in a string // can also be achieved using "square brackets" $string = 'abcdef'; echo $string[0]; // a echo $string[3]; // d echo $string[strlen($string)-1]; // f ?> Example #4 substr(3) casting behaviour <?php class apple { public function __toString() { return "green"; } } echo "1) ".var_export(substr("pear", 0, 2), true).PHP_EOL; echo "2) ".var_export(substr(54321, 0, 2), true).PHP_EOL; echo "3) ".var_export(substr(new apple(), 0, 2), true).PHP_EOL; echo "4) ".var_export(substr(true, 0, 1), true).PHP_EOL; echo "5) ".var_export(substr(false, 0, 1), true).PHP_EOL; echo "6) ".var_export(substr("", 0, 1), true).PHP_EOL; echo "7) ".var_export(substr(1.2e3, 0, 4), true).PHP_EOL; ?> The above example will output: 1) 'pe' 2) '54' 3) 'gr' 4) '1' 5) false 6) false 7) '1200' ERRORS
/EXCEPTIONS Returns FALSE on error. Example #5 <?php var_dump(substr('a', 1)); // bool(false) ?> SEE ALSO
strrchr(3), substr_replace(3), preg_match(3), trim(3), mb_substr(3), wordwrap(3), String access and modification by character. PHP Documentation Group SUBSTR(3)
All times are GMT -4. The time now is 05:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy