Using sed command to change each letter to the next one in the alphabet

Here is what is the file beast.txt: savage beast tank beauty

I am looking to get it to look like: tbwbhf cfbtu ubol cfbvuz

This what I have but when I run this it changes the letters to "[a-z]+1".

cat beast.txt | sed 's/[a-z]/[a-z]+1/g' > savage.txt

Do I have to use other special characters to in the sed command or should this be done with a loop? Thank you for your help.

2 answers

  • answered 2021-02-22 22:31 William Pursell

    This is not a job for sed:

    $ echo 'savage beast tank beauty' | tr a-z b-za
    tbwbhf cfbtu ubol cfbvuz
    

    If you really want to use sed, you can do:

    $ b2z=bcdefghijklmnopqrstuvwxyz
    $ echo 'savage beast tank beauty' | sed -e "y/a$b2z/${b2z}a/"
    tbwbhf cfbtu ubol cfbvuz
    

  • answered 2021-02-22 23:44 bildungsroman11

    I used this '$ echo 'savage beast tank beauty' | tr a-z b-za' and it worked.

    I am now having trouble reversing what I just did.