Visit Our UNIX and Linux User Community

Trying to make cryptogram script

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Trying to make cryptogram script
# 1  
Old 02-17-2016
Linux 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
# 2  
Old 02-17-2016
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.
# 3  
Old 02-17-2016
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.
# 4  
Old 02-17-2016
sed 's/m/^[[1;31mL^[[0m/g' file

to's mail yields
Dear RudiC,

jereESC[1;31mLESC[0myab5 has just replied to a thread you have subscribed to entitled -
Trying to ESC[1;31mLESC[0make cryptograESC[1;31mLESC[0m script - in the UNIX for DuESC[1;31mLESC[0mESC[1;31mLESC[0mies Questions &
Answers foruESC[1;31mLESC[0m of Unix & Linux ForuESC[1;31mLESC[0ms.

This thread is located at:
---------- 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:

# 5  
Old 02-17-2016
That's odd, when I use that piece of code on
I auwfgi twj jdgo aw nfhu dvwfj nramgb Ib jumsm xmsm dtrvwir mgam xuwn I otmx da xmgg. -umtsr idzIi juwsmdf
It gives me
I auwfgi twj jdgo aw nfhu dvwfj nra^[[1;31mL^[[0mgb Ib ju^[[1;31mL^[[0ms^[[1;31mL^[[0m x^[[1;31mL^[[0ms^[[1;31mL^[[0m dtrvwir ^[[1;31mL^[[0mga^[[1;31mL^[[0m xuwn I ot^[[1;31mL^[[0mx da x^[[1;31mL^[[0mgg. -u^[[1;31mL^[[0mtsr idzIi juws^[[1;31mL^[[0mdf
The two lines of code to get that output, respectively, are:
cat crypt.txt | tr k I

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

Thank you for your help
# 6  
Old 02-17-2016
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 [ .

Previous Thread | Next Thread
Test Your Knowledge in Computers #999
Difficulty: Easy
The trusted computing base (TCB) of a computer system is the set of all hardware, firmware, and/or software components that are critical to its security.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with a script to make makefile

How do we create a shell script that creates a makefile? what if we want to use the #include header files too? (2 Replies)
Discussion started by: sslokhan
2 Replies

2. UNIX for Dummies Questions & Answers

how to make script automated

if i have a script called file1=$(ls -l|awk '{print $9 $1}') awk ' /date_of_selling:/ { print $6 ":" &9 }' /$file1 >> data.txt if i wanna this script to run automatically every day at 8 am :D (3 Replies)
Discussion started by: teefa
3 Replies

3. Shell Programming and Scripting

how to run script? call other script? su to another user? make a cron?

Good morning. I am searching for "how-to"'s for some particular questions: 1. How to write a script in HP-UX 11. 2. How to schedule a script. 3. How to "call" scripts from the original script. 4. How to su to another user from within a script. This is the basics of what the... (15 Replies)
Discussion started by: instant000
15 Replies

4. Shell Programming and Scripting

Help to make the script simple

Hi All, I have a script which throws the output if condition matches. I run the cmd : # ldf Filesystem kbytes used avail capacity Mounted on /dev/dsk/c1t0d0s0 1984564 1375019 550009 72% / /dev/dsk/c1t0d0s3 5040814 2628410 2361996 53% /usr... (4 Replies)
Discussion started by: naw_deepak
4 Replies

5. Shell Programming and Scripting

How can I make a script to ftp over?

Hi, I have a script that ftp over the file: CFGFILE=/export/home/myuser/scripts/ftp1.cfg LOGFILE=/app/bea/logs/ LOCALPATH=/expport/home/myuser/ECNLogs/ YEAR=`date '+%Y'` MONTH=`date '+%m'` DAY=`date '+%d'` HOUR=`date '+%H'` MINUTE=`date '+%M'` LASTHOUR=$((HOUR-1)) echo $LASTHOUR ... (4 Replies)
Discussion started by: mehrdad68
4 Replies

6. Shell Programming and Scripting

How to make a script out of commands

Hi, I have a very basic knowledge of Unix and I need your help for a small script that will do the following commands that I do manually by just giving the filename TPR20080414.txt cut -d'|' -f3,4 TPR20080414.txt> oe_012.lkp awk -F "|" '{temp=$1;$1=$2;$2=temp}1' OFS="|" oe_012.lkp >... (3 Replies)
Discussion started by: sickboy
3 Replies

7. Shell Programming and Scripting

make directory script

Hi, I try to write a script to create a new directory. #!/bin/bash echo "Please enter folder name (6 characters only) :" read foldername mkdir /home/user/$foldername $foldername >> /home/list/list.txt My question/situation: 1) how to ensure the folder name MUST BE 6 characters... (0 Replies)
Discussion started by: malaysoul
0 Replies

8. Shell Programming and Scripting

Help make script much easier

Is there any method to realise this in one command? Thanks in advance (2 Replies)
Discussion started by: GCTEII
2 Replies

9. Shell Programming and Scripting

make my script wait

is there a way to make my script wait before doing something without using the "sleep _" command? (4 Replies)
Discussion started by: Blip
4 Replies

10. Programming

make script

I need to write a make script to install a C module in a UNIX environment.It should install the sources, build the libraries and install them and also install the info pages on the system. Can this script be general enough to also install on windows, windows dll, windows help file's etc. Any... (3 Replies)
Discussion started by: cherio
3 Replies

Featured Tech Videos