The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed string manipulation speedieB Shell Programming and Scripting 4 11-23-2008 08:27 PM
string manipulation james6 UNIX for Dummies Questions & Answers 5 06-03-2008 10:05 AM
String Manipulation Help shadow0001 Shell Programming and Scripting 4 03-09-2008 04:35 PM
string manipulation hai1973 Shell Programming and Scripting 13 08-20-2007 11:27 AM
awk string manipulation zoo591 Shell Programming and Scripting 2 08-09-2006 12:13 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-13-2008
Cactus Jack Cactus Jack is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 16
string manipulation

Hi, I have searched this long and hard and don’t seem to see another post on this issue.
I have two strings each with the same characters but in a different order.

String1=”word”
String2=”dwor”

I want to test them to show their similarity. Unfortunately I can’t do a sort so that they will be identical (dorw) as that only works on file. Can someone propose a non sed/awk way of doing this.

Thanks

C.J
  #2 (permalink)  
Old 02-13-2008
H2OBoodle H2OBoodle is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 18
Please indicate how you're defining "similarity"
  #3 (permalink)  
Old 02-13-2008
Cactus Jack Cactus Jack is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 16
sorry I meant identical. This is for the purposes of a test. The strings are already very similar. They only differ in the way of content by order. I want to run a command(s) on them so that they look the same.
  #4 (permalink)  
Old 02-13-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
but they can look the same in many different permutations, 96 I think for a four letter word. How do you know which permutation you want them to be identical too?
  #5 (permalink)  
Old 02-13-2008
Cactus Jack Cactus Jack is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 16
Can you a give a permutation for one that can be put in a test command?

I was hoping to manipulate them so they both are identical.

E.g. sort characters in order

string1=dorw
string2=dorw

They are identical and can be put in a test command, returning true. The strings already have the same length and letters so I thought there must be some way to get them like that.
  #6 (permalink)  
Old 02-14-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
very awkward method

Hi,

My solution is very awkward anc complex, but it works well in my PC.

So just try it, to be honest, i do not know how to sort a single string. Seems the split/sort/join are all working for a file but not a single string.

If you have found any good solution, do let me know. i am really curious about this thread.

Code:
echo "first string"
read str1
echo "second string"
read str2
echo $str1 | sed 's/./& /g' > temp1
echo $str2 | sed 's/./& /g' > temp2
for i in `cat temp1`
do
echo $i
done | sort > t1
for j in `cat temp2`
do
echo $j 
done | sort > t2
a=`comm -3 t1 t2 | wc -l`
if [ $a -le 0 ]
then
echo "similiar"
else
echo "different"
fi
rm temp1 temp2 t1 t2
  #7 (permalink)  
Old 02-14-2008
rein rein is offline
Registered User
  
 

Join Date: Dec 2004
Location: Zürich
Posts: 146
I'm not sure what you want to do. Do you want to proof the equality of the strings? eg. same length, same chars, same order? Or do you want to put one string of which you already have proven length and same chars in the same order as the first string? Or don't care about the order of either of them, as long as they're in the same order, whatever that order is?
Sponsored Links
Closed Thread

Bookmarks

Tags
perl, perl shift, shift, shift perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0