Sponsored Content
Full Discussion: Comparing strings
Top Forums UNIX for Advanced & Expert Users Comparing strings Post 302111710 by varungupta on Thursday 22nd of March 2007 08:04:08 AM
Old 03-22-2007
for string comparisions we generally use = operator.
-eq is used for integer comparisons.
if [ "str1" = "str2" ] then

fi

will do your task .
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

comparing two strings

Hi How do i compare two strings in shell script. Below is an example but I am not getting the desired output, plz help if then echo success fi I am not getting the desired output if I do this. plz help (24 Replies)
Discussion started by: ragha81
24 Replies

2. Shell Programming and Scripting

Comparing Two Strings

Hi All, While I am trying to run below code I Am getting the exception like ./abs.sh: line 102: syntax error near unexpected token `then' ./abs.sh: line 102: ` then' The Code Snippet is: if then cat $file1 | sed -e... (8 Replies)
Discussion started by: Anji
8 Replies

3. Shell Programming and Scripting

comparing strings

i have a string in a file which gets repeated number of times like below: rpttxt("abc") . . rpttxt("REP_TITLE") rpttxt("BOS_TITLE") . . . . and so on using awk or grep how can i comapre the string( as the second half keeps varying) and store it in a temporary variable? I am using the... (3 Replies)
Discussion started by: agarwal
3 Replies

4. Shell Programming and Scripting

comparing 2 strings

hi i have 2 strings. i want to compare the strings. please help (2 Replies)
Discussion started by: satish@123
2 Replies

5. Shell Programming and Scripting

comparing two strings

hi All i am facing prob in comparing two strings that have two word. below is the code snippet. checkValidates="file validates" file3_name="file" if then echo "file" $file3_name "is validated successfully" fi when i run this i get the error as -bash: [: too many arguments ... (1 Reply)
Discussion started by: infyanurag
1 Replies

6. Shell Programming and Scripting

Comparing strings using nawk

Hello All Please I have got a file called DATE.tex which consist of 01-04-2008_12:00:00 01-04-2005_12:00:00 01-04-2003_12:00:00 01-04-2007_12:00:00 01-04-2002_12:00:00 01-04-2009_12:00:00 I want to use nawk to print out the dates >=01-04-2009_12:00:00 I tried this cat plnt.new |... (6 Replies)
Discussion started by: ganiel24
6 Replies

7. Shell Programming and Scripting

Comparing strings with sed

Input: The the the the Output: not-same same What would be the sed command to do this? (7 Replies)
Discussion started by: cola
7 Replies

8. UNIX for Dummies Questions & Answers

Strings comparing incorrectly

Hello I'm very new to Linux and shell scripting so I only know basic stuff. I'm making a script with the purpose of finding the longest string or word in a file. Here's what I got so far: #!/bin/bash longest="" for i in $(strings -n $1); do if ] then longest=$i fi done echo $longest... (4 Replies)
Discussion started by: SCB
4 Replies

9. Shell Programming and Scripting

comparing strings as ints

Hi, So I got his code below. $year is a string of 2010,2011 etc. I guess I want to convert $year to an integer so I can do my if statement to see if the year string is greater than 2010? Or how could I do this? Right now I get a syntax error doing this. if; then do stuff fi (2 Replies)
Discussion started by: vsekvsek
2 Replies

10. Shell Programming and Scripting

Comparing Strings in ksh88

Hi I tried the following string comparison script in Ksh88 #!/bin/ksh str1='aC' str2='ABC' if then echo "Equal" else echo "Not Equal" fi Though str1 and str2 are not equal the script output says Equal . Please correct me Thanks (2 Replies)
Discussion started by: smile689
2 Replies
PROP_STRING(3)						   BSD Library Functions Manual 					    PROP_STRING(3)

NAME
prop_string, prop_string_create, prop_string_create_cstring, prop_string_create_cstring_nocopy, prop_string_copy, prop_string_copy_mutable, prop_string_size, prop_string_mutable, prop_string_cstring, prop_string_cstring_nocopy, prop_string_append, prop_string_append_cstring, prop_string_equals, prop_string_equals_cstring -- string value property object LIBRARY
Property Container Object Library (libprop, -lprop) SYNOPSIS
#include <prop/proplib.h> prop_string_t prop_string_create(void); prop_string_t prop_string_create_cstring(const char *cstring); prop_string_t prop_string_create_cstring_nocopy(const char *cstring); prop_string_t prop_string_copy(prop_string_t string); prop_string_t prop_string_copy_mutable(prop_string_t string); size_t prop_string_size(prop_string_t string); bool prop_string_mutable(prop_string_t string); char * prop_string_cstring(prop_string_t string); const char * prop_string_cstring_nocopy(prop_string_t string); bool prop_string_append(prop_string_t str1, prop_string_t str2); bool prop_string_append_cstring(prop_string_t string, const char *cstring); bool prop_string_equals(prop_string_t str1, prop_string_t str2); bool prop_string_equals_cstring(prop_string_t string, const char *cstring); DESCRIPTION
The prop_string family of functions operate on a string value property object type. prop_string_create(void) Create an empty mutable string. Returns NULL on failure. prop_string_create_cstring(const char *cstring) Create a mutable string that contains a copy of cstring. Returns NULL on failure. prop_string_create_cstring_nocopy(const char *cstring) Create an immutable string that contains a reference to cstring. Returns NULL on failure. prop_string_copy(prop_string_t string) Copy a string. If the string being copied is an immutable external C string reference, then the copy is also immutable and references the same external C string. Returns NULL on failure. prop_string_copy_mutable(prop_string_t string) Copy a string, always creating a mutable copy. Returns NULL on failure. prop_string_size(prop_string_t string) Returns the size of the string, not including the terminating NUL. If the supplied object isn't a string, zero is returned. prop_string_mutable(prop_string_t string) Returns true if the string is mutable. If the supplied object isn't a string, false is returned. prop_string_cstring(prop_string_t string) Returns a copy of the string's contents as a C string. The caller is responsible for freeing the returned buffer. In user space, the buffer is allocated using malloc(3). In the kernel, the buffer is allocated using malloc(9) using the malloc type M_TEMP. Returns NULL on failure. prop_string_cstring_nocopy(prop_string_t string) Returns an immutable reference to the contents of the string as a C string. If the supplied object isn't a string, NULL is returned. prop_string_append(prop_string_t str1, prop_string_t str2) Append the contents of str2 to str1, which must be mutable. Returns true upon success and false otherwise. prop_string_append_cstring(prop_string_t string, const char *cstring) Append the C string cstring to string, which must be mutable. Returns true upon success and false otherwise. prop_string_equals(prop_string_t str1, prop_string_t str2) Returns true if the two string objects are equivalent. prop_string_equals_cstring(prop_string_t string, const char *cstring) Returns true if the string's value is equivalent to cstring. SEE ALSO
prop_array(3), prop_bool(3), prop_data(3), prop_dictionary(3), prop_number(3), prop_object(3), proplib(3) HISTORY
The proplib property container object library first appeared in NetBSD 4.0. BSD
January 21, 2008 BSD
All times are GMT -4. The time now is 02:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy