Sponsored Content
Top Forums Shell Programming and Scripting problem in comparing numeric with string Post 302162192 by jaduks on Monday 28th of January 2008 09:18:05 AM
Old 01-28-2008
The one that yogesh is mentioning above should work for both numeric and string comparison. A different look of the same.

Code:
$ VAR=25
$ [ $VAR == "25" ] && echo "Y" || echo "N"
Y

$ VAR=25A
$ [ $VAR == "25A" ] && echo "Y" || echo "N"
Y

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert string to numeric

Hi, I have read some figures from a text file by getting the position and wish to do some checking, but it seem like it won't work. eg. my figure is 0.68 it still go the the else statement, it seems like it treat it as a text instead of number. Anybody can Help ? Thanks. # only... (3 Replies)
Discussion started by: kflee2000
3 Replies

2. Shell Programming and Scripting

numeric string and length

given a string passed to a program that supposed to be numeric and of a certain length say 8 digits - so say for e.g. need to verify this 01234567 How would I parse this string to validat it meet requirements I tried to use * | sed /\(\{8})/ Thanks in advance (1 Reply)
Discussion started by: dragrid
1 Replies

3. Programming

check the given string is numeric or not.

Hi, how to check the given string is numeric or not , without converting ( using strtol...). for ex: if string is C01 - non-numeric data if string is 001 - numeric data TIA (11 Replies)
Discussion started by: knowledge_gain
11 Replies

4. Shell Programming and Scripting

Extracting numeric from string

I have a file whose contents are: $ cat file1 cfd_V03R37 cfd_V03R38 tried sed 's///g' file1 > file2 $cat file1 0337 0338 Is there any way by which i can work on same file and write o/p to the same file instead of using file2 (3 Replies)
Discussion started by: vjasai
3 Replies

5. Shell Programming and Scripting

Problem comparing String using IF stmt

Hi frnds Im facing an issues while trying to compare string using IF stmt, my code is: chkMsgName=`Service Fee Detail` if then if then if then echo "Valid File Ready for processing" fi fi ... (5 Replies)
Discussion started by: balesh
5 Replies

6. Shell Programming and Scripting

Problem in comparing 2 files string by string

Hi Champs, I am a newbie to unix world, and I am trying to built a script which seems to be far tough to be done alone by me..... " I am having a raw csv file which contains around 50 fields..." From that file I have to grep 2 fields "A" and "B"....field "A" is to be aligned vertically... (11 Replies)
Discussion started by: jitendra.pat04
11 Replies

7. Shell Programming and Scripting

check if a string is numeric

I checked all the previous threads related to this and tried this. My input is all numbers or decimals greater than zero everytime. I want to check the same in the korn shell script. Just validate the string to be numeric. This is what I am doing. var="12345" if ) -o "$var" !=... (14 Replies)
Discussion started by: megha2525
14 Replies

8. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

9. Programming

C++ Get text and numeric value from a string

I have a string opt="row234" I want to put "row" in a string and 234 in an int. In general it should be opt="textnum" I want to store text in a string and num in an int. (6 Replies)
Discussion started by: kristinu
6 Replies

10. Shell Programming and Scripting

Extract all first numeric character from a string

Hello, I have a file of strings a below:- 4358RYFHD9845 28/COC/UYF984 9834URD 98HJDU I need to extract all the first numeric character of every sting as follows:- 4358 28 9834 thanks to suggest ASAP Regards, Jasi Use code tags, thanks. (7 Replies)
Discussion started by: jassi10781
7 Replies
UPSLOG(8)							    NUT Manual								 UPSLOG(8)

NAME
upslog - UPS status logger SYNOPSIS
upslog -h upslog [OPTIONS] DESCRIPTION
upslog is a daemon that will poll a UPS at periodic intervals, fetch the variables that interest you, format them, and write them to a file. The default format string includes variables that are supported by many common UPS models. See the description below to make your own. OPTIONS
-h Display the help message. -f format Monitor the UPS using this format string. Be sure to enclose format in quotes so your shell doesn't split it up. Valid escapes within this string are: %% Insert a single "%" %TIME format% Insert the time with strftime formatting %ETIME% Insert the number of seconds, ala time_t. This is now a 10 digit number. %HOST% insert the local hostname %UPSHOST% insert the host of the UPS being monitored %PID% insert the pid of upslog %VAR varname% insert the value of variable varname The default format string is: %TIME @Y@m@d @H@M@S% %VAR battery.charge% %VAR input.voltage% %VAR ups.load% [%VAR ups.status%] %VAR ups.temperature% %VAR input.frequency% -i interval Wait this many seconds between polls. This defaults to 30 seconds. If you require tighter timing, you should write your own logger using the upsclient(3) library. -l logfile Store the results in this file. You can use "-" for stdout, but upslog will remain in the foreground. -s ups Monitor this UPS. The format for this option is upsname[@hostname[:port]]. The default hostname is "localhost". -u username If started as root, upsmon will setuid(2) to the user id associated with username for security. If username is not defined, it will use the value that was compiled into the program. This defaults to "nobody", which is less than ideal. SERVICE DELAYS
The interval value is merely the number given to sleep(3) after running through the format string. Therefore, a query will actually take slightly longer than the interval, depending on the speed of your system. LOG ROTATION
upslog writes its PID to upslog.pid, and will reopen the log file if you send it a SIGHUP. This allows it to keep running when the log is rotated by an external program. SEE ALSO
Server: upsd(8) Clients: upsc(8), upscmd(8), upsrw(8), upsmon(8) Internet resources: The NUT (Network UPS Tools) home page: http://www.networkupstools.org/ Network UPS Tools 05/21/2012 UPSLOG(8)
All times are GMT -4. The time now is 09:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy