Trying to make cryptogram script

Hello everyone,

Relatively new to Linux but I'm trying to solve a problem.

I'm trying to make a cryptogram solver script where I use tr to easily replace the "cryptic" letters with the solved letters. I have the cryptogram as an all-lowercase text file crypt.txt. When I make replacements, the replacement letters will be uppercase to distinguish them.

My problem is that I also want those letters to change color.

I took this code from a different post I found from a search on these forums:

cat mylog | sed ''/START/s//`printf "\033[32mSTART\033[0m"`/''

and edited it for my use. My general format for letter replacing say, a "k" with an "L", is:

cat crypt.txt | tr k L | sed ''/L/s//`printf "\033[32mL\033[0m"`/''

but this only works if the letter is by itself e.g. not in the middle of a word. I've tried adding * to each side of L but was unsuccessful.

Any help would be appreciated! Thanks. This is my first post so hello everyone

Not sure what you want to achieve and where it fails - try

sed 's/k/^[[1;31mL^[[0m/g' file

The ^[ is the verbatim escape char, entered e.g. using <CTRL>v<ESC> from the command line.

Thanks rudic, I tried that code but nothing changed. I can get the original code I used to work as long as the objective letter is by itself e.g. not part of a 2+ letter word.

Applying

sed 's/m/^[[1;31mL^[[0m/g' file

to unix.com's mail yields

---------- Post updated at 18:08 ---------- Previous update was at 18:04 ----------

which on a terminal will look like

Dear RudiC,

jereLyab5 has just replied to a thread you have subscribed to entitled - 
Trying to Lake cryptograL script - in the UNIX for DuLLies Questions & 
Answers foruL of Unix & Linux ForuLs.

This thread is located at:
http://www.unix.coL/showthread.php?t=264178&goto=newpost

That's odd, when I use that piece of code on

It gives me

The two lines of code to get that output, respectively, are:

cat crypt.txt | tr k I

and

cat crypt.txt | tr k I | sed 's/m/^[[1;31mL^[[0m/g'

Thank you for your help

There's NO k in your text to be replaced! I'm using m as the target char.

DON'T cat the file, and DON'T tr the file. Use as given:

sed 's/m/^[[1;31mL^[[0m/g' crypt.txt
       ^--target ^--repl. char 

That changes lower case m to red upper case L , provided you enter the explicit <ESC> char and NOT two chars ^ and [ .