0

Is there any tool to replace some characters with another one but at once , i mean for example i have text file like this :

.>+&5+B0"0,9,04A?@"56/!3

Replace each of this character with another character, eg: . = H , > = E Is there any tool available so give it all characters in array and replace with another array of characters , i know ( wish ) i could do this with programming but wondering if there is any tool or technique within certain word processing software that can handle this kind of tricks ,

4
  • I'm curious about the "all at once" part - do all of the substitutions have to be made at once because you have things like A = B and B = C? Jun 12, 2012 at 14:08
  • What OS are you using?
    – Paul
    Jun 12, 2012 at 14:14
  • @Darth Android no all characters are unique , A = B , C = D , * = A and so on
    – echolab
    Jun 12, 2012 at 14:31
  • @Paul Linux Suse & Windows 7 Ultimate
    – echolab
    Jun 12, 2012 at 14:32

2 Answers 2

8

This is precisely the purpose of the program "tr". Naturally, you have to be using an OS that supports it (Linux, Cygwin, etc.)

cat myfile | tr 'ABCDEFGHIJ' '1234567890'
1
  • does this really do the trick i have openSuse , does this replace A = 1 , B = 2 , ....
    – echolab
    Jun 12, 2012 at 14:42
3

With sed available on Linux / Unix / MacOSX and some RegExp magic, you can quickly do any kind of text substitutions, e.g.:

sed -r "s:\.:H:g;s:>:E:g" < INPUT_FILE
3
  • Or sed 'y/.>/HE/'. Jun 12, 2012 at 14:33
  • could u describe this code , i mean what will get replaced with what so i can figure it out , am i able to write this script as long as full alphabetic replacement !?
    – echolab
    Jun 12, 2012 at 14:36
  • For sed 'y/.>/HE/', the code is in the form sed 'y/{CHAR SET TO BE REPLACED}/{REPLACEMENT CHAR SET}/' That means for A=>1, B=>2, C=>3, the code needed is sed 'y/ABC/123/'.
    – Ron Lau
    Jun 13, 2012 at 4:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .