# Replace Characters...

**URL:** <https://community.unix.com/t/replace-characters/166375>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [October 26, 2006, 2:59pm UTC](https://community.unix.com/t/replace-characters/166375 "2006-10-26T14:59:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lgardner17325](https://community.unix.com/letter_avatar/lgardner17325/32/5_5575768a8748004e209b776fc1b2916d.png) [@lgardner17325](https://community.unix.com/u/lgardner17325)\
**Post date:** [October 26, 2006, 2:59pm UTC](https://community.unix.com/t/replace-characters/166375/1 "2006-10-26T14:59:46Z")

</div>

In a file, How do I replace a set number of characters in each line?

For example.... substitute the first 54 characters of each line with mv?

Thanks!  
Lisa

---

<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:** [October 26, 2006, 4:18pm UTC](https://community.unix.com/t/replace-characters/166375/2 "2006-10-26T16:18:22Z")

</div>

'sed' is your friend - [sed1liners](http://www.pement.org/sed/sed1line.txt)

```plaintext
sed 's/^.\{54\}/mv/' myFile.txt

```

---

<div class="post-metadata">

**Author:** ![anbu23](https://community.unix.com/user_avatar/community.unix.com/anbu23/32/351_2.png) [@anbu23](https://community.unix.com/u/anbu23)\
**Post date:** [October 26, 2006, 4:20pm UTC](https://community.unix.com/t/replace-characters/166375/3 "2006-10-26T16:20:11Z")

</div>

```nohighlight
sed "s/^.\{54\}/mv/" x

```

---

<div class="post-metadata">

**Author:** ![lgardner17325](https://community.unix.com/letter_avatar/lgardner17325/32/5_5575768a8748004e209b776fc1b2916d.png) [@lgardner17325](https://community.unix.com/u/lgardner17325)\
**Post date:** [October 26, 2006, 4:39pm UTC](https://community.unix.com/t/replace-characters/166375/4 "2006-10-26T16:39:41Z")

</div>

Thank you so much.... it was exactly what I needed!!

Can I just ask.... is the "." considered a wildcard in this code?

---

<div class="post-metadata">

**Author:** ![anbu23](https://community.unix.com/user_avatar/community.unix.com/anbu23/32/351_2.png) [@anbu23](https://community.unix.com/u/anbu23)\
**Post date:** [October 26, 2006, 4:47pm UTC](https://community.unix.com/t/replace-characters/166375/5 "2006-10-26T16:47:01Z")

</div>

Yes "." matches any character

---

<div class="post-metadata">

**Author:** ![venu\_nbk](https://community.unix.com/letter_avatar/venu_nbk/32/5_5575768a8748004e209b776fc1b2916d.png) [@venu\_nbk](https://community.unix.com/u/venu_nbk)\
**Post date:** [October 26, 2006, 4:49pm UTC](https://community.unix.com/t/replace-characters/166375/6 "2006-10-26T16:49:28Z")

</div>

> [@vgersh99](#):
>
> 'sed' is your friend - [sed1liners](http://www.pement.org/sed/sed1line.txt)
> 
> ```plaintext
> sed 's/^.\{54\}/mv/' myFile.txt
> 
> ```

vgersh99

I have a doubt in this. If i am inside the file that is  
vi myFile.txt.  
Then how can I use the command, should I use the sed word?

---

<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:** [October 26, 2006, 4:56pm UTC](https://community.unix.com/t/replace-characters/166375/7 "2006-10-26T16:56:28Z")

</div>

no, but use the same 'substitute' expression in the vi 'command' mode.

---

<div class="post-metadata">

**Author:** ![venu\_nbk](https://community.unix.com/letter_avatar/venu_nbk/32/5_5575768a8748004e209b776fc1b2916d.png) [@venu\_nbk](https://community.unix.com/u/venu_nbk)\
**Post date:** [October 26, 2006, 4:59pm UTC](https://community.unix.com/t/replace-characters/166375/8 "2006-10-26T16:59:07Z")

</div>

> [@vgersh99](#):
>
> no, but use the same 'substitute' expression in the vi 'command' mode.

Thanks,

could you please explain me what does this command mean?

:%s/crmrl01/crmpl01/g

---

<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:** [October 26, 2006, 5:04pm UTC](https://community.unix.com/t/replace-characters/166375/9 "2006-10-26T17:04:50Z")

</div>

```nohighlight
:%s/crmrl01/crmpl01/g

```

```nohighlight
: - vi command 'mode'
% - for ALL the lines in the files
s - substutute the following:
     string 'crmrl01' with string 'crmpl01'
g - Globally for each line [not just once (by default), byut for multiple occorences of
      string 'crmrl01'

```
