Sponsored Content
Full Discussion: String Comparision
Top Forums Shell Programming and Scripting String Comparision Post 302555941 by AhmedLakadkutta on Friday 16th of September 2011 07:11:45 AM
Old 09-16-2011
String Comparision

I want to compare two strings using awk dynamically without trimming the spaces and want to find the count of matching string.
Code:
Input Strings file:
File1 content (file1):
" a        "
" a2       "
File2 content (file2):
" a        "
" a        "
" a2       "
" b2       "
" c2       "

Please correct the following code i want exact string matching and not similar matching without trimming the spaces.

Code:
while read uid
do
{
 cn=`cat file2 | awk -v k=$uid '$1 ~ k' |wc -l`
        if [ $cn -ge 1 ]
        then
   echo "String and count=$uid  $cn"
       fi
} 
done < file1

Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

while - comparision

Hi, Please find the attached scriplet and suggest me to fix the bug in this. ----------------------------------- noofdirs=`ls *.tar | wc -l` if ; then let i=1 while ( $i <= $noofdirs ) ; do echo $i mkdir $i file1=`ls *.tar | head -1` mv $file1 $i i =... (2 Replies)
Discussion started by: sharif
2 Replies

2. Shell Programming and Scripting

String comparision in shell scripting

Hi Guys, I am new to scripting I have written a code to compare strings,but I am getting some Exception Code snippet: MODE="D" if ]; then . $file1 fi Error: ./BatchJobs.sh: [[: execute permission denied I have given all Execute permissions to the script(chmod 755... (2 Replies)
Discussion started by: Anji
2 Replies

3. UNIX for Dummies Questions & Answers

problem in string comparision

Hi All, I've to compare the number of records present in a file against its trailer count. for ex: rec_cnt=$(awk 'END{print NR}' file.txt) trl_cnt=$(tail -1 file.txt| cut -c1-6) problem is trailer is appended with zero's and while comparing it is giving problem. i.e, rec_cnt=9 and... (1 Reply)
Discussion started by: ganapati
1 Replies

4. Shell Programming and Scripting

comparision of string in various files

i want to take position 19-24(only first line) from all files and need to compare any duplication is there or not. If duplication, then i have to print the file names. I have written to take the characters from 19-24 from all files. but how to compare ? ... (1 Reply)
Discussion started by: senthil_is
1 Replies

5. Shell Programming and Scripting

reg String comparision

Hi, I would like to compare the 25th position of the file with the character '(' and if it is not equal then it would generate a mail. I have used the below if condition, however it is always executing the code within if, even the comparison is expected to return false. if Please help me... (1 Reply)
Discussion started by: kdheepan
1 Replies

6. Shell Programming and Scripting

Date - String comparision

Hi, I am having difficulty to compare a string in a file against a date from a a table and print the latest date. Below are the values. String in File : 2009-12-02 00:37:51 Value Table : 2010-01-10-02.00.49.294758 I have to compare both the values ( Ignore the Microsecond in the table... (5 Replies)
Discussion started by: sam_78_nyc
5 Replies

7. Shell Programming and Scripting

String comparision not working

have written a simple shell script to do some automation work. Basically the script searches for all the files in the current path and if the file is a specified one, it does some action. Below are the relevant lines --- #!/bin/bash 1.for i in ls * 2.do 3.if 4.then .... //do something... (3 Replies)
Discussion started by: Dev_Sharma987
3 Replies

8. Shell Programming and Scripting

String comparision

I have a string like ab or abc of whatever length. But i want to know whether another string ( for example, abcfghijkl, OR a<space> bcfghijkl ab<space> cfghijkl OR a<space>bcfghijkl OR ab<space> c<space> fghijkl ) starts with ab or abc... space might existing on the longer string... If so, i... (1 Reply)
Discussion started by: nram_krishna@ya
1 Replies

9. Shell Programming and Scripting

awk: string followed by tab comparision

Hi all, Currently i am using if( $0~/ NOT / && $0~/ NULL /) { ................. } to check if the input record contains "NOT" and "NULL". But in some cases "NOT" and "NULL" are preceded and followed by tab. How do i find compare for these fields as well? (3 Replies)
Discussion started by: ysvsr1
3 Replies

10. Shell Programming and Scripting

Test command non case specific string comparision

Hi, I want to do caseless string comparision using test command for eg: Ind_f="y" test "$Ind_f" == "y|Y" i tried , ** , nothing worked. any thoughts on how to do case insensitive string comparison using test command without converting to any particular case using typeset or tr? (8 Replies)
Discussion started by: Kulasekar
8 Replies
VARIANT_CMP(3)								 1							    VARIANT_CMP(3)

variant_cmp - Compares two variants

SYNOPSIS
int variant_cmp (mixed $left, mixed $right, [int $lcid], [int $flags]) DESCRIPTION
Compares $left with $right. This function will only compare scalar values, not arrays or variant records. PARAMETERS
o $left - The left operand. o $right - The right operand. o $lcid - A valid Locale Identifier to use when comparing strings (this affects string collation). o $flags -$flags can be one or more of the following values OR'd together, and affects string comparisons: Variant Comparision Flags +--------------------+----------------------------------+ | value | | | | | | | meaning | | | | +--------------------+----------------------------------+ | | | | NORM_IGNORECASE | | | | | | | Compare case insensitively | | | | | | | |NORM_IGNORENONSPACE | | | | | | | Ignore nonspacing characters | | | | | | | |NORM_IGNORESYMBOLS | | | | | | | Ignore symbols | | | | | | | | NORM_IGNOREWIDTH | | | | | | | Ignore string width | | | | | | | |NORM_IGNOREKANATYPE | | | | | | | Ignore Kana type | | | | | | | |NORM_IGNOREKASHIDA | | | | | | | Ignore Arabic kashida characters | | | | +--------------------+----------------------------------+ Note As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the "VARIANT" class. COM and DOTNET objects will have the value of their default property taken and used as the variant value. The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add(3) in PHP cor- responds to VarAdd() in the MSDN documentation. RETURN VALUES
Returns one of the following: Variant Comparision Results +------------+---------------------------------------+ | value | | | | | | | meaning | | | | +------------+---------------------------------------+ | | | | VARCMP_LT | | | | | | | $left is less than $right | | | | | | | | VARCMP_EQ | | | | | | | $left is equal to $right | | | | | | | | VARCMP_GT | | | | | | | $left is greater than $right | | | | | | | |VARCMP_NULL | | | | | | | Either $left, $right or both are NULL | | | | +------------+---------------------------------------+ PHP Documentation Group VARIANT_CMP(3)
All times are GMT -4. The time now is 07:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy