Sponsored Content
Full Discussion: string to number
Top Forums Shell Programming and Scripting string to number Post 40175 by kowrip on Wednesday 10th of September 2003 03:07:06 PM
Old 09-10-2003
You didn't mention which shell you are using. Form Bourne shell or bash shell, the following comparison operators exist for comparing integer values:

int1 -eq int2 True if integer one is equal to integer two
int1 -ge int2 True if integer one is greater than or equal to integer two
int1 -gt int2 True if integer one is greater than integer two
int1 -le int2 True if integer one is less than or equal to integer two
int1 -lt int2 True if interger one is less then interger two.
int1 -ne int2 True if integer one is not equal to integer two

So, you should be able to do something like:

if [ $SIZE1 -gt $SIZE2 ]
then
...
else
...
fi
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell to number and to string

Hello Does the unix korn shell provide a function to convert between number and string data-types regards Hrishy (1 Reply)
Discussion started by: xiamin
1 Replies

2. Shell Programming and Scripting

$A is a number / any other string? How to determine ?

I have a variable (say $A) and while passing it gets either a number or some other string. Now how can test (with if else) whether the variable is just a ne or something else ? Thanks a lot to all in advance C Saha (2 Replies)
Discussion started by: csaha
2 Replies

3. Shell Programming and Scripting

extracting a number from a string

Hi everyone, I have a string as follow ts1n65ulpa4096x16m16_130a_ss1p08v125c i would like to extract 4096 and 16 from string and save it into two variable. but this string could also have the form ts1n65ulpa32x16m16_130a_ss1p08v125c therefore the number before "x" could be 2 or 3 digits. i use... (6 Replies)
Discussion started by: ROOZ
6 Replies

4. UNIX for Dummies Questions & Answers

Number of lines containing a certain string

Hey I want to know if there is an option to know the number of lines containing a certain string (bit for example) in a file? Say I want to know number of lines containing only the string BIT in file xyz. I know how to get number of lines in a file by using wc -l but how do you get number of lines... (1 Reply)
Discussion started by: #moveon
1 Replies

5. Shell Programming and Scripting

number of characters in a string

Hi there, I have some user input in a variable called $VAR, and i need to ensure that the string is 5 or less characters .... does anybody know how i can count the characters in the variables ? any help would be great, cheers (2 Replies)
Discussion started by: rethink
2 Replies

6. Shell Programming and Scripting

Python String <--> Number

My question is so simple: A = raw_input("A ") if A == '56': VAR = (A + 54)/13 else: print "other operations" if I write in input 5656565656 i want to make some arithmetic operations if the first input is 56XXX but the output is TypeError: cannot concatenate 'str' and... (2 Replies)
Discussion started by: kazikamuntu
2 Replies

7. Shell Programming and Scripting

string to number problem

Hi actually what happen i have taken a value from database table and stored in variable and that value is 20100601 000000 but this value is stored as string value in database table so after storing this value in variable a when i did operation on this a variable like a=`expr ${a} +1` i m... (1 Reply)
Discussion started by: aishsimplesweet
1 Replies

8. Shell Programming and Scripting

changing number in bash (number is in form of string)

I have a txt file as database. when i run my program what it does is it ask me for 3 name and stored in the file as name1:name2:name3:1 when u enter 3 name it add those in file as above format and add 1 at the end. I what i want is if i enter same names again it changes that 1 to 2 and so... (3 Replies)
Discussion started by: Learnerabc
3 Replies

9. Shell Programming and Scripting

Getting number from a string

I have a string c12 and want to get the number 12 In general instead of 12 I can have any number. I have to capture the number as I need to do some computations on it. I am using a bash script (6 Replies)
Discussion started by: kristinu
6 Replies

10. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies
ExperimentFile(3)						  Staden Package						 ExperimentFile(3)

NAME
exp_read_info, exp_fread_info, exp_create_info, exp_destroy_info, exp_create_range, exp_extract_range, exp_get_feature_index, exp_get_int, exp_get_rng, exp_get_str, exp_put_int, exp_put_rng, exp_put_str, exp_print_line, exp_print_seq, exp_print_file, opos2str, str2opos, conf2str, str2conf - Manipulations of the Experiment File format SYNOPSIS
#include <expFileIO.h> Exp_info *exp_read_info( char *file); Exp_info *exp_fread_info( FILE *fp); Exp_info *exp_create_info(); void exp_destroy_info( Exp_info *e); char *exp_create_range( char *str, int start, int end); int exp_extract_range( char *str, int *start, int *end); int exp_get_feature_index( char *e); int exp_get_int( Exp_info *e, int id, int *val); int exp_get_rng( Exp_info *e, int id, int *from, int *to); int exp_get_str( Exp_info *e, int id, char *s, f_implicit s_l); int exp_put_int( Exp_info *e, int id, int *val); int exp_put_rng( Exp_info *e, int id, int *from, int *to); int exp_put_str( Exp_info *e, int id, char *s, f_implicit s_l); int exp_print_line( FILE *fp, Exp_info *e, int eflt, int i); int exp_print_seq( FILE *fp, Exp_info *e, int eflt, int i); void exp_print_file( FILE *fp, Exp_info *e); char *opos2str( int2 *opos, int len, char *buf); int str2opos( int2 *opos, char *buf); char *conf2str( int1 *conf, int len, char *buf); int str2conf( int1 *conf, char *buf); DESCRIPTION
These functions manipulate Experiment Files. They include functions for reading, writing, and editing the files. The principle structure used by the routines is the Exp_info structure. This is as follows. #define MAXIMUM_EFLT_LENGTH 4 #define MAXIMUM_EFLTS 48 #define EXP_FILE_LINE_LENGTH 128 typedef Array Exp_entries; typedef struct { Array entries[MAXIMUM_EFLTS]; /* array of array of entries */ int Nentries[MAXIMUM_EFLTS]; /* array of number of entries */ FILE *fp; } Exp_info; #define NULL_Exp_info ( (Exp_info *) NULL ) For the purposes of simple and efficient coding, each line on an experiment file must be smaller than the defined EXP_FILE_LINE_LENGTH, which is 128 characters. Many functions take an experiment file line type identifier as an argument. These functions are listed in the prototypes as taking int id. Here id should be specified using one of the macros defining in the header file. They take the form of EFLT_XX where XX is the line type. For instance, the ID line type identifier should be written as EFLT_ID. The C functions available follow. Some FORTRAN interfaces are also available, but these are not documented. See the include file for their prototypes. exp_read_info and exp_fread_info read an experiment file into an allocated Exp_info structure. If successful, the structure pointer is return. Otherwise the null pointer is returned. exp_create_info allocates and initialises a new, blank, Exp_info structure. If successful, the structure pointer is return. Otherwise the null pointer is returned. exp_destroy_info deallocates an Exp_info structure. exp_create_range creates a string using the experiment file range format of "start..stop". This format is used by the AQ, ON, TG and TC line types. The buffer specified should be large enough to hold the string. The function returns the str pointer supplied as an argument. exp_extract_range extracts the start and end values from the string representation of a range; "start..stop". The values are stored in the integer pointers sent as arguments. If successful, the function returns 0. Otherwise -1 is returned. exp_get_feature_index converts from a string representation of an experiment file line type to the integer value. For example, exp_get_fea- ture_index("SQ") returns the integer 22, which is the same as the EFLT_SQ definition. exp_get_int obtains the integer value held in a specific line type. The value is stored in the integer pointer val. If successful, the function returns 0. Otherwise 1 is returned. exp_get_rng obtains the range values held in a specific line type. The values are stored in the integer pointers from and to. If success- ful, the function returns 0. Otherwise 1 is returned. exp_get_str obtains the string value held in a specific line type. The value is stored in the string s. At most s_l characters are copied. If successful, the function returns 0. Otherwise 1 is returned. exp_put_int writes the integer pointed to by val to the specified line type. If successful, the function returns 0. Otherwise 1 is returned. exp_put_rng writes the range pointed to by from and to to the specified line type. If successful, the function returns 0. Otherwise 1 is returned. exp_put_str writes the string s of length s_l to the specified line type. If successful, the function returns 0. Otherwise 1 is returned. exp_print_line outputs all entries of the specified type to the specified file pointer. exp_print_seq exp_print_file outputs all entries of all line types to the specified file pointer. opos2str converts an array of original positions held in opos with len elements to a string suitable for use in the ON line type. The buf should be large enough to hold the string, which in the worst case will be 4 * sequence length. Returns buf. str2opos converts the experiment file original position string held in buf to an array of original positions to be stored in opos. opos must be large enough to hold the data, hence it should be of the same length as the sequence. Returns the number of elements written to the opos array. conf2str converts an array of confidence values helf in confR with len elements to a string suitable for use in the AV line type. The buf should be large enough to hold the string, which in the worst case will be 4 * sequence length. Returns buf. str2conf convers the experiment file confidence values string held in buf to an array of confidence values to be stored in conf. conf must be large enough to hold the data, hence it should be of the same length as the sequence. Returns the number of elements written to the conf array. SEE ALSO
ExperimentFile(4) ExperimentFile(3)
All times are GMT -4. The time now is 08:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy