Pages

Shell Script--Character Replace By Next Character


Write a shell script to encrypt the content of a file using logic .

 (i) Replace a character by just next character in the cycle for example A by B ( or a by b), B by C (or b   by c), Y by Z (or y by z), Z by A ( or z by a).


(ii) Leave numbers and any other symbols unchanged.


#!/bin/bash
str=""
echo " enter a file name "
read str
cat $str | tr '[abcdefghijklmnopqrstuvwxyz]' '[bcdefghijklmnopqrstuvwxyza]' | tr '[ABCDEFGHIJKLMNOPQRSTUVWXUZ]' '[BCDEFGHIJKLMNOPQRSTUVWXUZA]' >output.txt
cat output.txt