# SH Script help. editing string

**URL:** <https://community.unix.com/t/sh-script-help-editing-string/215978>\
**Category:** Shell Programming and Scripting\
**Created:** [October 10, 2008, 8:44pm UTC](https://community.unix.com/t/sh-script-help-editing-string/215978 "2008-10-10T20:44:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nookie](https://community.unix.com/letter_avatar/nookie/32/5_5575768a8748004e209b776fc1b2916d.png) [@nookie](https://community.unix.com/u/nookie)\
**Post date:** [October 10, 2008, 8:44pm UTC](https://community.unix.com/t/sh-script-help-editing-string/215978/1 "2008-10-10T20:44:53Z")

</div>

I have a string that looks like this

username|field1|field2|field3

the data has a delimiter of "|"  
how can i edit field1, keeping the rest of the data the same  
also how can i edit field2 and 3.

---

<div class="post-metadata">

**Author:** ![vidyadhar85](https://community.unix.com/user_avatar/community.unix.com/vidyadhar85/32/997_2.png) [@vidyadhar85](https://community.unix.com/u/vidyadhar85)\
**Post date:** [October 10, 2008, 8:51pm UTC](https://community.unix.com/t/sh-script-help-editing-string/215978/2 "2008-10-10T20:51:10Z")

</div>

edit in the sense you want to replace the first field with some other word keeping other intact??  
if so use awk

```nohighlight
echo "username|field1|field2|field3"|awk -F\| '{print "word|"$2"|"$3"|"$4}'

```

output will be  
word|field1|field2|field3  
same way you can do your second question also

---

<div class="post-metadata">

**Author:** ![nookie](https://community.unix.com/letter_avatar/nookie/32/5_5575768a8748004e209b776fc1b2916d.png) [@nookie](https://community.unix.com/u/nookie)\
**Post date:** [October 10, 2008, 9:00pm UTC](https://community.unix.com/t/sh-script-help-editing-string/215978/3 "2008-10-10T21:00:18Z")

</div>

\> edit in the sense you want to replace the first field with some other word keeping other intact??  
yup that was what i meant

that is very simple to understand.  
thank you very much

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [October 10, 2008, 10:34pm UTC](https://community.unix.com/t/sh-script-help-editing-string/215978/4 "2008-10-10T22:34:38Z")

</div>

No need for any external commands:

```nohighlight
string="username|field1|field2|field3"
newfield1=something
newstring="$newfield1|${string#*|}"

```
