![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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. |
|
||||
|
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 |
|
||||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Tags |
| perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|