Sed to handle newline specific name modifiication


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed to handle newline specific name modifiication
# 1  
Old 06-19-2009
Sed to handle newline specific name modifiication

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


Last edited by vasanth_vadalur; 06-19-2009 at 06:43 AM.. Reason: tab and space is there in fron of words....
# 2  
Old 06-19-2009
Please share what you have tried? then we will be able to help you better.
# 3  
Old 06-19-2009
sed need to see the next line and with specific TAB

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
# 4  
Old 06-19-2009
Ok, but have you tried anything to solve the problem for yourself?

Regards
# 5  
Old 06-19-2009
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
# 6  
Old 06-19-2009
something like this ?

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

# 7  
Old 06-19-2009
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 ----------

Quote:
Originally Posted by panyam
something like this ?

Code:
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert a newline after match in files of specific name under some subdirectories?

Hi I'd like to add the newline: \tuser: nobody", or "<TAB>user: nobody to all files named: docker-compose.ymlin subfolders of pwd with names beginning with 10-20. Within these files, I'd like to find the line (there'll only be one) containing: command: celery workerNOTE: As far as... (2 Replies)
Discussion started by: duncanbetts
2 Replies

2. Shell Programming and Scripting

How to replace NewLine with comma using sed?

Hi , I have a huge file with following records and I want to replace the last comma with ',NULL'. I try using SED but could not create a correct script . In my opinion I need a script which can convert ,/n with ,NULL/n 1,CHANGE_MEMBER,2010-12-28 00:05:00, 2,CHANGE_MEMBER,2012-09-02... (8 Replies)
Discussion started by: Ajaypal
8 Replies

3. Shell Programming and Scripting

Why SED can't see the last newline character?

Removed. My question does not make sense. and SED does see the last newline character. But I still have a question: How to remove the last newline character(the newline character at the end of last line) using SED? ---------- Post updated 05-01-11 at 10:51 AM ---------- Previous update was... (7 Replies)
Discussion started by: kevintse
7 Replies

4. Shell Programming and Scripting

AWK/SED: handle max chars in a line

Hi all, I hope you guys can help me. I prefer SED/AWK solutions if possible. For my shame it didn't work for me :o ISSUE: :wall: 1\3 1/$4\@7\ 1234567890123456789\ 1234567890123456789,\ 1234567890123456789\ 123456789012 12345 1234567890123456789\ 1234567890123456789,\ 1234... (5 Replies)
Discussion started by: unknown7
5 Replies

5. Shell Programming and Scripting

sed newline

Hi everyone, I'd like to use the script validatehtml which returns either the given url is HTML strict or not, using http:// validator . w3 . org . sh validatehtml #!/bin/bash wget -q http:// validator . w3 .org / check?uri=$1 cat check\?uri\=$1 | sed -n '/h2/ p' | sed 's/ */ /g' | sed... (2 Replies)
Discussion started by: azertyazerty
2 Replies

6. Shell Programming and Scripting

sed newline to tab ,problem

Input: gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly sed 's/\n/\t/g' infile It's not working. Output should be: gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly (5 Replies)
Discussion started by: cola
5 Replies

7. Shell Programming and Scripting

using awk removing newline and specific position

Hello Friends, Input File looks as follows: >FASTA Header1 line1 line2 line3 linen >FASTA Header2 Line1 Line2 linen >FASTA Header3 and so on ....... Output: Want something as: >FASTA Header1 line1line2line3linen >FASTA Header2 (5 Replies)
Discussion started by: Deep9000
5 Replies

8. Shell Programming and Scripting

add newline in file after finding specific text

Hi All, I am tring to insert a newline with "/" in a text file whenever there is the text "end;" right now I have inside file: . . end; I want to have: . . end; / I tried doing the following within the file :g/^end;/s//end; \/ / (4 Replies)
Discussion started by: jxh461
4 Replies

9. Shell Programming and Scripting

Sed to handle newline specific name modifiication

Hi, The below link clarification required... https://www.unix.com/shell-programming-scripting/112523-sed-handle-newline-specific-name-modifiication.html Vasanth (1 Reply)
Discussion started by: vasanth_vadalur
1 Replies

10. Shell Programming and Scripting

how to handle variables in sed

while read line do str1=`grep 'customernumberR11' file1 | cut -c 20-21` str2=`grep 'newnumberR11' file1 | cut -c 15-16` if ; then sed -e "s/newnumberR11/ s/$str2/\$str1/g" $line fi done < file1 (4 Replies)
Discussion started by: LAKSHMI NARAYAN
4 Replies
Login or Register to Ask a Question