The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[sh] String comparison operators userix Shell Programming and Scripting 1 05-16-2008 01:09 AM
string comparison fedora Shell Programming and Scripting 2 01-03-2007 11:20 AM
String Comparison between two files using awk rudoraj Shell Programming and Scripting 7 07-25-2006 08:04 AM
string comparison operators, what are they?? ballazrus Shell Programming and Scripting 11 02-13-2006 03:30 AM
String Comparison abey High Level Programming 1 10-19-2005 09:08 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-01-2008
Registered User
 

Join Date: Feb 2008
Location: London, UK
Posts: 4
string comparison

Hello experts,

(tcsh shell)

Quite new to shell scripting...

I have got a file with a single word on each line. Want to be able to make a comparison such that i can read pairs of words that are ROT13 to each other. Also, i would like to print the pairs to another file.

Any help appreciated....

Thanks in advance !
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-02-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 218
Given e.g.

Code:
#  cat rotfile
hello
world
uryyb
this
is
a
test
n
grfg
file
Following will pull out all matching rot 13 pairs:

Code:
#  for x in `cat rotfile`; do y=`echo $x  | tr '[a-z]' '[n-z][a-m]'`;if [ `grep $y rotfile` ]; then  echo $x $y; fi; done | awk '{arr[$1]=$2;if ( arr[$2] != $1 ){print $0}}'
hello uryyb
a n
test grfg

HTH,
Reply With Quote
  #3 (permalink)  
Old 02-02-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 218
oh yeah - and make it:

Code:
for x in `cat rotfile`; do y=`echo $x  | tr '[a-z]' '[n-z][a-m]'`;if [ `grep $y rotfile` ]; then  echo $x $y; fi; done | awk '{arr[$1]=$2;if ( arr[$2] != $1 ){print $0}}' > rotfile.out
to send your output to the file rotfile.out
Reply With Quote
  #4 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: Feb 2008
Location: London, UK
Posts: 4
Appreciate it !
Can understand it and it aint that complicated ! Its just that i am quite new to this type of programming and running out of time as this was just something I had to get out of the way !

Thanks !!
Reply With Quote
  #5 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: Feb 2008
Location: London, UK
Posts: 4
got a question....

have tried the above and works perfectly for all small files. But for very large files, comes up with error saying 'too many arguments' !

Any solution for this?

Thanks again.
Reply With Quote
  #6 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: Feb 2008
Location: London, UK
Posts: 4
Development to my previous post !!

What i did find out was that the error mesg - 'too many arguments' was due to having numbers in the file as well, instead of just characters !

the code does not work with numbers in the file. It only works for files with characters only. Sorry should have mentioned earlier, got numbers in some of my files too !!!

Can you help me out here. I am trying as well.

Thanks
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0