Sponsored Content
Top Forums Shell Programming and Scripting Check in awk about a value of variable Post 302302168 by Franklin52 on Monday 30th of March 2009 09:18:37 AM
Old 03-30-2009
Quote:
Originally Posted by tal
I need to check if a variable have numeric value and if yes how many digits does it have, how do i do it?
Something like this?

Code:
awk 'int(var) == var {print length(var)}'

Regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check if a variable contains a .

Hi I am writing a bash script and would like to check is a variable contains a . or not ex. a=102 output ok a=1.02 output not ok Many thanks, (3 Replies)
Discussion started by: gekkos
3 Replies

2. Shell Programming and Scripting

Check if a variable has a value assigned?

Hi, I want to check if a variable has a value assigned to it or not. I can do following - cat $Var > File1 if then echo "$Var has value" else echo "$Var is null" fi But I have to check for 3 Variables and I want to wrap it up in couple of unix statements. Any... (3 Replies)
Discussion started by: sumeet
3 Replies

3. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

4. Shell Programming and Scripting

Check if a variable is zero

I have seen many posts for this sort of problem but I just did not know how to use it for my issue. A number is assigned to a variable and I wanted to check if it is a zero or non zero. Example of my numbers are below: 000000000000000000000000000000000000000000000000... (8 Replies)
Discussion started by: soujiv
8 Replies

5. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 Replies

6. Shell Programming and Scripting

Check the value of a variable

#!/bin/sh echo "Running Script to capture ORACLE Erros" # Change Directory to the actual logs path cd /home/nv8510/lognew err_var=`grep -in "ORA-" *` if then echo "THESE ARE THE ORACLE ERROR OCCURED" echo "$err_var" echo... (7 Replies)
Discussion started by: neeraj617
7 Replies

7. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

8. Shell Programming and Scripting

Check if a variable is having value

I have a script /root/asas with following contents. #!/bin/bash ha=`cat /etc/passwd | grep sandra` if ; then echo "Sandra is in /etc/passwd" echo "variable ha is $ha" else echo "Sandra is NOT in /etc/passwd" echo "variable ha is $ha" fi What... (3 Replies)
Discussion started by: anil510
3 Replies

9. Shell Programming and Scripting

Check variable

Hi people, I would like to start a review of my config variable to check whether they have been changed and if not then there is only an echo. If they have been changed to my other commands are executed. I hope you can help me. with best regards JPad edit: here my code if ;... (8 Replies)
Discussion started by: JPad
8 Replies

10. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies
EMPTY(3)								 1								  EMPTY(3)

empty - Determine whether a variable is empty

SYNOPSIS
bool empty (mixed $var) DESCRIPTION
Determine whether a variable is considered to be empty. A variable is considered empty if it does not exist or if its value equals FALSE. empty(3) does not generate a warning if the variable does not exist. PARAMETERS
o $var - Variable to be checked Note Prior to PHP 5.5, empty(3) only supports variables; anything else will result in a parse error. In other words, the follow- ing will not work: empty(trim($name)). Instead, use trim($name) == false. No warning is generated if the variable does not exist. That means empty(3) is essentially the concise equivalent to !isset($var) || $var == false. RETURN VALUES
Returns FALSE if $var exists and has a non-empty, non-zero value. Otherwise returns TRUE. The following things are considered to be empty: o "" (an empty string) o 0 (0 as an integer) o 0.0 (0 as a float) o "0" (0 as a string) o NULL o FALSE o array() (an empty array) o $var; (a variable declared, but without a value) CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.5.0 | | | | | | | empty(3) now supports expressions, rather than | | | only variables. | | | | | 5.4.0 | | | | | | | Checking non-numeric offsets of strings returns | | | TRUE. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 A simple empty(3) / isset(3) comparison. <?php $var = 0; // Evaluates to true because $var is empty if (empty($var)) { echo '$var is either 0, empty, or not set at all'; } // Evaluates as true because $var is set if (isset($var)) { echo '$var is set even though it is empty'; } ?> Example #2 empty(3) on String Offsets PHP 5.4 changes how empty(3) behaves when passed string offsets. <?php $expected_array_got_string = 'somestring'; var_dump(empty($expected_array_got_string['some_key'])); var_dump(empty($expected_array_got_string[0])); var_dump(empty($expected_array_got_string['0'])); var_dump(empty($expected_array_got_string[0.5])); var_dump(empty($expected_array_got_string['0.5'])); var_dump(empty($expected_array_got_string['0 Mostel'])); ?> Output of the above example in PHP 5.3: bool(false) bool(false) bool(false) bool(false) bool(false) bool(false) Output of the above example in PHP 5.4: bool(true) bool(false) bool(false) bool(false) bool(true) bool(true) NOTES
Note Because this is a language construct and not a function, it cannot be called using variable functions. Note When using empty(3) on inaccessible object properties, the __isset() overloading method will be called, if declared. SEE ALSO
isset(3), __isset(), unset(3), array_key_exists(3), count(3), strlen(3), The type comparison tables. PHP Documentation Group EMPTY(3)
All times are GMT -4. The time now is 02:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy