# Sed to handle newline specific name modifiication

**URL:** <https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840>\
**Category:** Shell Programming and Scripting\
**Created:** [June 19, 2009, 5:40am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840 "2009-06-19T05:40:22Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![vasanth\_vadalur](https://community.unix.com/letter_avatar/vasanth_vadalur/32/6_449c533f586939b6e5f246632a46421f.png) [@vasanth\_vadalur](https://community.unix.com/u/vasanth_vadalur)\
**Post date:** [June 19, 2009, 5:40am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/1 "2009-06-19T05:40:22Z")

</div>

Hi,

Using sed, i need to edit two functions data as explained below.

C1 function axis need to be change as axis1 and in C2 function width and height name should change as width2 and height2.

Input file :

c1 {  
width=0  
text=Pen  
height=0  
axis=no  
mode=6  
}

c2 {  
width=1  
height=1  
type=pen  
mode=3  
axis=no  
}

Desired output:

c1 {  
width=0  
text=Pen  
height=0  
axis1=no  
mode=6  
}

c2 {  
width2=1  
height2=1  
type=pen  
mode=3  
axis=no  
}

Thanks in Advance  
Vasanth

---

<div class="post-metadata">

**Author:** ![rakeshawasthi](https://community.unix.com/user_avatar/community.unix.com/rakeshawasthi/32/224_2.png) [@rakeshawasthi](https://community.unix.com/u/rakeshawasthi)\
**Post date:** [June 19, 2009, 6:06am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/2 "2009-06-19T06:06:00Z")

</div>

Please share what you have tried? then we will be able to help you better.

---

<div class="post-metadata">

**Author:** ![vasanth\_vadalur](https://community.unix.com/letter_avatar/vasanth_vadalur/32/6_449c533f586939b6e5f246632a46421f.png) [@vasanth\_vadalur](https://community.unix.com/u/vasanth_vadalur)\
**Post date:** [June 19, 2009, 6:06am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/3 "2009-06-19T06:06:44Z")

</div>

Hi,

The above input and output file data does not showing the initial TAB space characters.

3 TAB space is present in the front of C1 and C2 function objects.

Note:

First the program need to search c2 then in the next line, after three tab space "width" word should be replaced with "width2". Then in the next line, after three tab space, the "height" word should be replaced as "height2".

The other function width and height should not be changed.

Thanks in Advance,  
Vasanth

---

<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:** [June 19, 2009, 6:11am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/4 "2009-06-19T06:11:03Z")

</div>

Ok, but have you tried anything to solve the problem for yourself?

Regards

---

<div class="post-metadata">

**Author:** ![vasanth\_vadalur](https://community.unix.com/letter_avatar/vasanth_vadalur/32/6_449c533f586939b6e5f246632a46421f.png) [@vasanth\_vadalur](https://community.unix.com/u/vasanth_vadalur)\
**Post date:** [June 19, 2009, 6:15am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/5 "2009-06-19T06:15:34Z")

</div>

Hi Rakesh,

I tried the below code, but it not working..

Eg:

sed -e 's/[]_c2[]\*{\*\n\*\t_width/c2[]{\n\twidth2/g'

Thanks in advance...

---------- Post updated at 05:15 AM ---------- Previous update was at 05:11 AM ----------

Hi Franklin,

I tried the above code.

Kindly clarify where i made mistake.

Thanks  
Vasanth

---

<div class="post-metadata">

**Author:** ![panyam](https://community.unix.com/letter_avatar/panyam/32/6_449c533f586939b6e5f246632a46421f.png) [@panyam](https://community.unix.com/u/panyam)\
**Post date:** [June 19, 2009, 6:17am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/6 "2009-06-19T06:17:38Z")

</div>

something like this ?

```nohighlight
awk -F"=" '/c1 \{/,/\}/ {OFS="=";if($1=="axis") $1="axis1"; }\
 /c2 \{/,/\}/ {if($1=="width") $1="width2" ; if($1=="height") $1="height2" }\
 { print }' input_file.txt

```

---

<div class="post-metadata">

**Author:** ![vasanth\_vadalur](https://community.unix.com/letter_avatar/vasanth_vadalur/32/6_449c533f586939b6e5f246632a46421f.png) [@vasanth\_vadalur](https://community.unix.com/u/vasanth_vadalur)\
**Post date:** [June 19, 2009, 7:00am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/7 "2009-06-19T07:00:30Z")

</div>

Hi panyam,

Its worked. Fine and Thanks a lot...

Thanks  
Vasanth

---------- Post updated at 05:50 AM ---------- Previous update was at 05:44 AM ----------

Sorry Panyam,

This code converting the full first feild, separated by = field separator.

I want in specific function....

Thanks  
Vasanth

---------- Post updated at 05:53 AM ---------- Previous update was at 05:50 AM ----------

Thanks in advance,  
Vasanth

---------- Post updated at 06:00 AM ---------- Previous update was at 05:53 AM ----------

> [@panyam](#):
>
> something like this ?
> 
> ```plaintext
> awk -F"=" '/c1 \{/,/\}/ {OFS="=";if($1=="axis") $1="axis1"; }\
> /c2 \{/,/\}/ {if($1=="width") $1="width2" ; if($1=="height") $1="height2" }\
> { print }' input_file.txt
> 
> ```

kindly reply

---

<div class="post-metadata">

**Author:** ![panyam](https://community.unix.com/letter_avatar/panyam/32/6_449c533f586939b6e5f246632a46421f.png) [@panyam](https://community.unix.com/u/panyam)\
**Post date:** [June 19, 2009, 7:09am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/8 "2009-06-19T07:09:05Z")

</div>

Hi Vasanth,

I did not get , what the problem your facing. for your reference i am attaching the data i tested and the output i got.

---

<div class="post-metadata">

**Author:** ![vasanth\_vadalur](https://community.unix.com/letter_avatar/vasanth_vadalur/32/6_449c533f586939b6e5f246632a46421f.png) [@vasanth\_vadalur](https://community.unix.com/u/vasanth_vadalur)\
**Post date:** [June 19, 2009, 8:00am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/9 "2009-06-19T08:00:42Z")

</div>

Dear Panyam,

Thanks. But my input file is little different, i am attaching for your reference.

While posting, the tab space character is removed.

Thanks  
Vasanth

---

<div class="post-metadata">

**Author:** ![vasanth\_vadalur](https://community.unix.com/letter_avatar/vasanth_vadalur/32/6_449c533f586939b6e5f246632a46421f.png) [@vasanth\_vadalur](https://community.unix.com/u/vasanth_vadalur)\
**Post date:** [June 19, 2009, 8:02am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/10 "2009-06-19T08:02:09Z")

</div>

For the above input file, the awk script is failing to give desired output.

Thanks In advance,  
Vasanth

---

<div class="post-metadata">

**Author:** ![panyam](https://community.unix.com/letter_avatar/panyam/32/6_449c533f586939b6e5f246632a46421f.png) [@panyam](https://community.unix.com/u/panyam)\
**Post date:** [June 19, 2009, 8:15am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/11 "2009-06-19T08:15:25Z")

</div>

adding a tab solves the problem.

```nohighlight
awk -F"=" '/c1 \{/,/\}/ {OFS="=";if($1==" axis") $1=" axis1"; }\
 /c2 \{/,/\}/ {if($1==" width") $1=" width2" ; if($1==" height") $1=" height2" }\
 { print }' input_file.txt

"[TAB key]axis"

```

---

<div class="post-metadata">

**Author:** ![vasanth\_vadalur](https://community.unix.com/letter_avatar/vasanth_vadalur/32/6_449c533f586939b6e5f246632a46421f.png) [@vasanth\_vadalur](https://community.unix.com/u/vasanth_vadalur)\
**Post date:** [June 19, 2009, 8:36am UTC](https://community.unix.com/t/sed-to-handle-newline-specific-name-modifiication/242840/12 "2009-06-19T08:36:03Z")

</div>

Thanks...

Vasanth
