[Solved] String integer comparison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] String integer comparison
# 8  
Old 01-31-2014
sh in Linux is a link to bash, that's not a problem.

There's no reason why this should not work. I suggest you remove the lines (possible control character (most likely ^M)) and paste them again from some post in this thread.

Code:
[root@admin2 tmp]# ./s1
: integer expression expected
[root@admin2 tmp]# cat -v s1
value=$(sed -n "/^LoggingLevel=/{s/.*=//;p;q;}" file)

if [ $value -gt 2^M ]; then
  echo more than 2
fi

This User Gave Thanks to Scott For This Post:
# 9  
Old 02-01-2014
no Sir, still the same error

i even typed the statement to avoid any copy paste errors

still the same :integer expression expected error
# 10  
Old 02-01-2014
Then, I suggest your input file has the ^M character.

Please post the output of cat -v from both your script and the input file.
This User Gave Thanks to Scott For This Post:
# 11  
Old 02-01-2014
Thanks a ton for catching that. the input file did have ^M. I deleted the file and recreated it and the IF statement works fine. Thanks again for your time.
# 12  
Old 02-01-2014
Great!

Hindsight's a wonderful thing, but if I'd been more awake, we could have solved this an hour ago Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] How to extract integer out of a string?

Input: XXX:1,XXX:3,XXX:3 Output: A=1 B=3 C=3 Below code is what i do currently. However it doesn't work out for all cases. As some times the last digit extracted is giving me error. It cant be used for arithmetic computation. Any better methods out there? If possible, can you... (9 Replies)
Discussion started by: bananamen
9 Replies

2. Shell Programming and Scripting

[Solved] String Comparison

Hi I am beginner in writing shell scripting please tell me how to compare a string in Unix shell. i have two variables in a shell script, var1="00101 00201 00301 303 401 405" var2="101 201 301" i want to compare var1 with var2 . for example if 101 from Var1 present in Var2 or not. similarly... (5 Replies)
Discussion started by: nikesh29
5 Replies

3. Shell Programming and Scripting

[Solved] need to convert decimal to integer

Using below command awk 'NR==FNR{A=$1;next} {sum+=($2*A)}END{OFMT="%20f";print int(sum)}' Market.txt Product.txt answer:351770174.00000 how to convert this to 351770174. when i try with below command i am getting different result. awk 'NR==FNR{A=$1;next}... (3 Replies)
Discussion started by: katakamvivek
3 Replies

4. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

5. Programming

[Solved] how to send an integer via message queue?

how can i send an integer via message queue? i try this, but it doesn't work, child process receive 13345943 instead of 5 #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/msg.h> #include <sys/ipc.h> #include <sys/sem.h> #include <errno.h> #include <unistd.h>... (2 Replies)
Discussion started by: tafazzi87
2 Replies

6. Shell Programming and Scripting

Doubt in integer comparison

Hi What is the difference between following commands Command1 length=1 if ] ; then echo "Hellow world" fi Command 2 length=1 if ] ; then echo "Hellow world" fi which is correct usage from this (2 Replies)
Discussion started by: morbid_angel
2 Replies

7. UNIX for Dummies Questions & Answers

Counting vowels in string. "Comparison pointer-integer".

I'm trying to write a programme which scans strings to find how many vowels they contain. I get an error saying that I'm trying to compare a pointer and an integer inif(*v == scanme){. How can I overcome this ? Also, the programme seems to scan only the first word of a string e.g.: if I type "abc... (1 Reply)
Discussion started by: fakuse
1 Replies

8. Programming

warning: comparison between pointer and integer

Hi guys :D I am still playing with my C handbook and yes, as you can see I have small problem as always :cool: I wrote a C code #include <stdio.h> #define MESSAGE 100 int main(void) { char input_mes - Pastebin.com And when I try to compile it I get following errors from gcc ... (1 Reply)
Discussion started by: solaris_user
1 Replies

9. Shell Programming and Scripting

integer comparison in ksh

Hi, I am just trying to compare integer in ksh. can you please tell me what's wrong with this code... or give me suggestions on alternative. sample code: i=0; if ; then echo inside if fi Thanks in advance! (6 Replies)
Discussion started by: nram_krishna@ya
6 Replies

10. Programming

comparison between pointer and integer

I received a warning when I tried to compile my program that said: warning: comparison between pointer and integer Could you please explain to me what this means, and in what ways I could possibly fix this? Thanks for your help! (2 Replies)
Discussion started by: sjung10
2 Replies
Login or Register to Ask a Question