# String replace

**URL:** <https://community.unix.com/t/string-replace/278717>\
**Category:** Shell Programming and Scripting\
**Created:** [December 7, 2010, 10:25am UTC](https://community.unix.com/t/string-replace/278717 "2010-12-07T10:25:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![srichunduru](https://community.unix.com/letter_avatar/srichunduru/32/5_5575768a8748004e209b776fc1b2916d.png) [@srichunduru](https://community.unix.com/u/srichunduru)\
**Post date:** [December 7, 2010, 10:25am UTC](https://community.unix.com/t/string-replace/278717/1 "2010-12-07T10:25:35Z")

</div>

I have a 100 liners in a file and every line looks like  
line 1  
AB://abcd.01/ABCDE/ABC.Monitor/tags/Release\_0.39.16.200/db/ABC/01-DML.sql  
line 2  
BC://abcd.01/ABCDE/ABC.Monitor/tags/Release\_0.39.16.200/db/ABC/02-DML.sql

How do i cut the characters from Release\_0.39.16.200/db/ABC/ in a shell.  
I try to use field seperator in awk some how does not give me the way i want.  
Please help ..

---

<div class="post-metadata">

**Author:** ![ctsgnb](https://community.unix.com/letter_avatar/ctsgnb/32/5_5575768a8748004e209b776fc1b2916d.png) [@ctsgnb](https://community.unix.com/u/ctsgnb)\
**Post date:** [December 7, 2010, 10:43am UTC](https://community.unix.com/t/string-replace/278717/2 "2010-12-07T10:43:23Z")

</div>

Do your lines have a fixed length ?  
if yes you can use

```nohighlight
cut -c ...

```

otherwise

```nohighlight
read a
b=${a#*//*/*/*/*/} 
echo ${b%/*}/

```

```nohighlight
# a="BC://abcd.01/ABCDE/ABC.Monitor/tags/Release_0.39.16.200/db/ABC/02-DML.sql"
# echo $a
BC://abcd.01/ABCDE/ABC.Monitor/tags/Release_0.39.16.200/db/ABC/02-DML.sql
# b=${a#*//*/*/*/*/}
# echo ${b%/*}/
Release_0.39.16.200/db/ABC/

```

---

<div class="post-metadata">

**Author:** ![cabrao](https://community.unix.com/letter_avatar/cabrao/32/5_5575768a8748004e209b776fc1b2916d.png) [@cabrao](https://community.unix.com/u/cabrao)\
**Post date:** [December 7, 2010, 10:49am UTC](https://community.unix.com/t/string-replace/278717/3 "2010-12-07T10:49:01Z")

</div>

Is it this you are looking for?

```nohighlight
$ awk -F/ '{print $7,$8,$9FS}' OFS=/ file
Release_0.39.16.200/db/ABC/
Release_0.39.16.200/db/ABC/

```

---

<div class="post-metadata">

**Author:** ![ctsgnb](https://community.unix.com/letter_avatar/ctsgnb/32/5_5575768a8748004e209b776fc1b2916d.png) [@ctsgnb](https://community.unix.com/u/ctsgnb)\
**Post date:** [December 7, 2010, 10:57am UTC](https://community.unix.com/t/string-replace/278717/4 "2010-12-07T10:57:29Z")

</div>

Or if you need the trailing / you can do it with awk also :

```nohighlight
awk -F/ '{print $7,$8,$9,x}' OFS=/ infile
Release_0.39.16.200/db/ABC/
Release_0.39.16.200/db/ABC/

```

---

<div class="post-metadata">

**Author:** ![cabrao](https://community.unix.com/letter_avatar/cabrao/32/5_5575768a8748004e209b776fc1b2916d.png) [@cabrao](https://community.unix.com/u/cabrao)\
**Post date:** [December 7, 2010, 11:24am UTC](https://community.unix.com/t/string-replace/278717/5 "2010-12-07T11:24:33Z")

</div>

I forgot the last slash, thanks ctsgnb 😉

---

<div class="post-metadata">

**Author:** ![ctsgnb](https://community.unix.com/letter_avatar/ctsgnb/32/5_5575768a8748004e209b776fc1b2916d.png) [@ctsgnb](https://community.unix.com/u/ctsgnb)\
**Post date:** [December 7, 2010, 11:25am UTC](https://community.unix.com/t/string-replace/278717/6 "2010-12-07T11:25:34Z")

</div>

no pb dude 😃

---

<div class="post-metadata">

**Author:** ![srichunduru](https://community.unix.com/letter_avatar/srichunduru/32/5_5575768a8748004e209b776fc1b2916d.png) [@srichunduru](https://community.unix.com/u/srichunduru)\
**Post date:** [December 7, 2010, 4:29pm UTC](https://community.unix.com/t/string-replace/278717/7 "2010-12-07T16:29:34Z")

</div>

Thankyou every one for your great help..

---

<div class="post-metadata">

**Author:** ![rdcwayx](https://community.unix.com/letter_avatar/rdcwayx/32/5_5575768a8748004e209b776fc1b2916d.png) [@rdcwayx](https://community.unix.com/u/rdcwayx)\
**Post date:** [December 7, 2010, 6:13pm UTC](https://community.unix.com/t/string-replace/278717/8 "2010-12-07T18:13:25Z")

</div>

use `cut` directly.

```nohighlight
cut -d \/ -f7- < infile

```

---

<div class="post-metadata">

**Author:** ![ctsgnb](https://community.unix.com/letter_avatar/ctsgnb/32/5_5575768a8748004e209b776fc1b2916d.png) [@ctsgnb](https://community.unix.com/u/ctsgnb)\
**Post date:** [December 8, 2010, 3:21am UTC](https://community.unix.com/t/string-replace/278717/9 "2010-12-08T03:21:19Z")

</div>

> [@rdcwayx](#):
>
> use `cut` directly.
> 
> ```plaintext
> cut -d \/ -f7- < infile
> 
> ```

almost ... you need to get rid off the trailing [^/]\*.sql chain
