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
Please share what you have tried? then we will be able to help you better.
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
Ok, but have you tried anything to solve the problem for yourself?
Regards
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
panyam
June 19, 2009, 6:17am
6
something like this ?
awk -F"=" '/c1 \{/,/\}/ {OFS="=";if($1=="axis") $1="axis1"; }\
/c2 \{/,/\}/ {if($1=="width") $1="width2" ; if($1=="height") $1="height2" }\
{ print }' input_file.txt
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 ----------
kindly reply
panyam
June 19, 2009, 7:09am
8
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.
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
For the above input file, the awk script is failing to give desired output.
Thanks In advance,
Vasanth
panyam
June 19, 2009, 8:15am
11
adding a tab solves the problem.
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"