# Unix/Linux shell script help

**URL:** <https://boards.straightdope.com/t/unix-linux-shell-script-help/808016>\
**Category:** Factual Questions\
**Created:** [February 2, 2018, 11:15am UTC](https://boards.straightdope.com/t/unix-linux-shell-script-help/808016 "2018-02-02T11:15:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Batano](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@Batano](https://boards.straightdope.com/u/Batano)\
**Post date:** [February 2, 2018, 11:15am UTC](https://boards.straightdope.com/t/unix-linux-shell-script-help/808016/1 "2018-02-02T11:15:55Z")

</div>

I used to know this stuff cold, but it has been a couple of decades. I want to create a shell script that reads links of text and replaces characters with a sequence of 1 to 3 other characters. For example, a-\>g, b-\>fd, c-\>xgh, d-\>k, etc. So “abcd” would be output as “gfdxghk”.

---

<div class="post-metadata">

**Author:** ![septimus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/septimus/32/410_2.png) [@septimus](https://boards.straightdope.com/u/septimus)\
**Post date:** [February 2, 2018, 11:33am UTC](https://boards.straightdope.com/t/unix-linux-shell-script-help/808016/2 "2018-02-02T11:33:42Z")

</div>

> [@Batano](#):
>
> I used to know this stuff cold, but it has been a couple of decades. I want to create a shell script that reads links of text and replaces characters with a sequence of 1 to 3 other characters. For example, a-\>g, b-\>fd, c-\>xgh, d-\>k, etc. So “abcd” would be output as “gfdxghk”.

Would the following filter accomplish what you want?  
sed -e s/a/g/g -e s/b/fd/g -e s/c/xgh/g -e s/d/k/g  
This actually changes “abcd” to “gfkxghk” since the ‘d-\>k’ production operates after the ‘b-\>fd’ production. You’ll want to specify what behavior you want in such cases.

---

<div class="post-metadata">

**Author:** ![Batano](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@Batano](https://boards.straightdope.com/u/Batano)\
**Post date:** [February 2, 2018, 11:40am UTC](https://boards.straightdope.com/t/unix-linux-shell-script-help/808016/3 "2018-02-02T11:40:31Z")

</div>

Cool, that looks like it will do the trick.
