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 !

Given e.g.

#  cat rotfile
hello
world
uryyb
this
is
a
test
n
grfg
file

Following will pull out all matching rot 13 pairs:

#  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,

oh yeah - and make it:

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 :slight_smile:

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 !!

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.

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