# Adding Characters to a Word List

**URL:** <https://community.unix.com/t/adding-characters-to-a-word-list/269050>\
**Category:** Shell Programming and Scripting\
**Created:** [July 7, 2010, 12:53pm UTC](https://community.unix.com/t/adding-characters-to-a-word-list/269050 "2010-07-07T12:53:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![evillion](https://community.unix.com/letter_avatar/evillion/32/6_449c533f586939b6e5f246632a46421f.png) [@evillion](https://community.unix.com/u/evillion)\
**Post date:** [July 7, 2010, 12:53pm UTC](https://community.unix.com/t/adding-characters-to-a-word-list/269050/1 "2010-07-07T12:53:18Z")

</div>

If I had a word list with a large amount of words in it, how would I (using a unix command) add, say, 123 to the end of each word?

EDIT: The word list is stored in a large text file. I need a command that applies the ending to each word in the file and saves the result in a new text file.

---

<div class="post-metadata">

**Author:** ![pseudocoder](https://community.unix.com/user_avatar/community.unix.com/pseudocoder/32/666_2.png) [@pseudocoder](https://community.unix.com/u/pseudocoder)\
**Post date:** [July 7, 2010, 1:19pm UTC](https://community.unix.com/t/adding-characters-to-a-word-list/269050/2 "2010-07-07T13:19:58Z")

</div>

Something like

```nohighlight
$ echo 'myword1 myword2 myword3' | sed 's/\([]\{0,1\}.[^]*\)/\1123/g'
myword1123 myword2123 myword3123
$ 

```

😕

---

<div class="post-metadata">

**Author:** ![Franklin52](https://community.unix.com/user_avatar/community.unix.com/franklin52/32/500_2.png) [@Franklin52](https://community.unix.com/u/Franklin52)\
**Post date:** [July 7, 2010, 1:23pm UTC](https://community.unix.com/t/adding-characters-to-a-word-list/269050/3 "2010-07-07T13:23:30Z")

</div>

Another one:

```nohighlight
echo a b c d | 
awk '$NF=$NF "123"' OFS="123 " 

```

---

<div class="post-metadata">

**Author:** ![evillion](https://community.unix.com/letter_avatar/evillion/32/6_449c533f586939b6e5f246632a46421f.png) [@evillion](https://community.unix.com/u/evillion)\
**Post date:** [July 7, 2010, 1:24pm UTC](https://community.unix.com/t/adding-characters-to-a-word-list/269050/4 "2010-07-07T13:24:51Z")

</div>

Hmm thats great, but is there one command that would obtain text from a text file with the word list in it, apply the ending, then save a new text file?

---

<div class="post-metadata">

**Author:** ![vgersh99](https://community.unix.com/user_avatar/community.unix.com/vgersh99/32/14851_2.png) [@vgersh99](https://community.unix.com/u/vgersh99)\
**Post date:** [July 7, 2010, 1:26pm UTC](https://community.unix.com/t/adding-characters-to-a-word-list/269050/5 "2010-07-07T13:26:00Z")

</div>

```nohighlight
echo 'myword1 myword2 myword3' | sed 's/[^][^]*/&123/g'

```

---

<div class="post-metadata">

**Author:** ![pseudocoder](https://community.unix.com/user_avatar/community.unix.com/pseudocoder/32/666_2.png) [@pseudocoder](https://community.unix.com/u/pseudocoder)\
**Post date:** [July 7, 2010, 1:28pm UTC](https://community.unix.com/t/adding-characters-to-a-word-list/269050/6 "2010-07-07T13:28:04Z")

</div>

```nohighlight
sed 's/\([]\{0,1\}.[^]*\)/\1123/g' wordlistfile > newfile

```

---

<div class="post-metadata">

**Author:** ![Franklin52](https://community.unix.com/user_avatar/community.unix.com/franklin52/32/500_2.png) [@Franklin52](https://community.unix.com/u/Franklin52)\
**Post date:** [July 7, 2010, 1:30pm UTC](https://community.unix.com/t/adding-characters-to-a-word-list/269050/7 "2010-07-07T13:30:36Z")

</div>

> [@evillion](#):
>
> Hmm thats great, but is there one command that would obtain text from a text file with the word list in it, apply the ending, then save a new text file?

```plaintext
awk '$NF=$NF "123"' OFS="123 " list > new_file

```

---

<div class="post-metadata">

**Author:** ![evillion](https://community.unix.com/letter_avatar/evillion/32/6_449c533f586939b6e5f246632a46421f.png) [@evillion](https://community.unix.com/u/evillion)\
**Post date:** [July 7, 2010, 1:55pm UTC](https://community.unix.com/t/adding-characters-to-a-word-list/269050/8 "2010-07-07T13:55:32Z")

</div>

Thanks Franklin52!

---------- Post updated at 01:53 PM ---------- Previous update was at 01:35 PM ----------

> [@franklin52](#):
>
> ```plaintext
> awk '$NF=$NF "123"' OFS="123 " list > new_file
> 
> ```

Your code worked for a small list, but when trying a big list it put "123" on the next line, instead of attached to a word:

Word  
123  
Word  
123  
...

Instead of

Word123  
Word123  
...

Any thoughts?
