Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.
String to int/float conversion
Name: sathyaprasad Date: June 25, 2007 at 02:36:44 Pacific OS: Solaris CPU/Ram: Sun Product: Sun
Comment:
Hello all, I am trying to read the 5th column of a log file which is the percentage filled space for a logical drive. I am writing a script which throws up a warning if this is greater than 60. But j is taken as a string and when I compare with 60 in the if statement, it does not work. How can I change string/ascii to int or float in shell so that the comparison works?
j=`echo $line | tr -s ' ' ' ' | cut -d' ' -f5` if [ $j -gt 60 ] then echo "WARNING:$line" fi
Summary: I am look for a shell script to scan all files in the system to find out if a file contains a particular string. If yes, then write the file name, path and line number containing the searching string ...
Summary: The awk solution above is best for what you are trying to do. However, floating point can be done in the shell by piping a string to bc. An example: #!/bin/sh IFS=, string="0" while read col1 col2 d...
Summary: In the following script when I get SIZE1 and SIZE2, they are of type string. I can not do any mathematical operations(especially comparing which file has more byte size) on them. I wanted to find ou...