Sponsored Content
Top Forums Shell Programming and Scripting Check in awk about a value of variable Post 302302172 by joeyg on Monday 30th of March 2009 09:27:33 AM
Old 03-30-2009
Hammer & Screwdriver Another approach

I added the "nope" to make it easier to see the output.

Code:
> echo 159a | awk '{ink2=ink=$0;lenx=length(ink); gsub("[:alpha:]","",ink2); leny=length(ink2); if (lenx==leny){print lenx}else{print "nope"}}'
nope
> echo 159a1 | awk '{ink2=ink=$0;lenx=length(ink); gsub("[:alpha:]","",ink2); leny=length(ink2); if (lenx==leny){print lenx}else{print "nope"}}'
nope
> echo 1591 | awk '{ink2=ink=$0;lenx=length(ink); gsub("[:alpha:]","",ink2); leny=length(ink2); if (lenx==leny){print lenx}else{print "nope"}}'
4
> echo a1591 | awk '{ink2=ink=$0;lenx=length(ink); gsub("[:alpha:]","",ink2); leny=length(ink2); if (lenx==leny){print lenx}else{print "nope"}}'
nope

 

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

NAME
dhcpdump - DHCP packet dumper SYNOPSIS
dhcpdump [-h regular-expression] DESCRIPTION
This command parses the output of tcpdump to display the dhcp-packets for easier checking and debugging. USAGE
tcpdump -lenx -s 1500 port bootps or port bootpc | dhcpdump If you want to filter a specific Client Hardware Address (CHADDR), then you can specifiy it as a regular expressions: tcpdump -lenx -s 1500 port bootps or port bootpc | dhcpdump -h ^00:c0:4f This will display only the packets with Client Hardware Addresses which start with 00:c0:4f. OUTPUT
TIME: 15:45:02.084272 IP: 0.0.0.0.68 (0:c0:4f:82:ac:7f) > 255.255.255.255.67 (ff:ff:ff:ff:ff:ff) OP: 1 (BOOTPREQUEST) HTYPE: 1 (Ethernet) HLEN: 6 HOPS: 0 XID: 28f61b03 SECS: 0 FLAGS: 0 CIADDR: 0.0.0.0 YIADDR: 0.0.0.0 SIADDR: 0.0.0.0 GIADDR: 0.0.0.0 CHADDR: 00:c0:4f:82:ac:7f:00:00:00:00:00:00:00:00:00:00 SNAME: . FNAME: . OPTION: 53 ( 1) DHCP message type 3 (DHCPREQUEST) OPTION: 54 ( 4) Server identifier 130.139.64.101 OPTION: 50 ( 4) Request IP address 130.139.64.143 OPTION: 55 ( 7) Parameter Request List 1 (Subnet mask) 3 (Routers) 58 (T1) 59 (T2) At the option field, the first field is the value of the option, the second one (between brackets) is the length of the option-datafield, the third field is the name of the option, the fourth field is the data of the option. RETURN VALUES
Always 0. NOTES
Privileged access is often needed for tcpdump. BUGS
Not all the parameter options are printed verbose, because of lack of documentation. Not all the options are tested, because of lack of clients/servers with these options. If you have a dump of one of them, please send them to me and I'll incorperate them. THANKS TO
Ralph Droms and Ted Lemons "The DHCP Handbook", ISBN 1-57870-137-6. Peter Apian-Bennewitz <apian@ise.fhg.de> for his Client Hardware Address filtering AUTHOR
Edwin Groothuis, edwin@mavetju.org (http://www.mavetju.org) SEE ALSO
dhcpd(8), tcpdump(1), RFC2132 November 21, 2003 November 21, 2003 DHCPDUMP(1)
All times are GMT -4. The time now is 06:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy