pacifique irakoze
pacifique irakoze

Reputation: 49

how to Replace all characters A and c from input to Z and e respectively

without using sed or awk

I tried this command to solve this problem

tr Ac Ze

but this command doesn't work Does any help, please?

Upvotes: 0

Views: 3598

Answers (1)

Adrian
Adrian

Reputation: 420

You can use sed command:

  • g: Apply the replacement to all matches to the regexp, not just the first.
  • s: stand for substitute
$ -> echo Aca | sed 's/A/Z/g; s/c/e/g'
Zea

Or just use tr command as said @James

$ -> echo Aca | tr Ac Ze
Zea

Another example:

#!/bin/bash

read -p "Insert word: " word
echo $word | tr Ac Ze

Result:

Insert word: Aca
Zea

Or:

#!/bin/bash

read -p "Insert word: " word
echo $word | sed 's/A/Z/g; s/c/e/g' 

Aditional info:

  • tr
$ -> whatis tr
tr (1)               - translate or delete characters
  • sed
$ -> whatis sed
sed (1)              - stream editor for filtering and transforming text

Upvotes: 2

Related Questions