how to replace a text of line with a comment line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to replace a text of line with a comment line
# 1  
Old 05-19-2009
Error how to replace a text of line with a comment line

I want to replace this line : "test compare [property get [findObject ":dlgGotoLine.lineNumText"] visible] true" and make it "#test compare [property get [findObject ":dlgGotoLine.lineNumText"] visible] true".
How can I do it ? And it should be checked in many sub folder files also.
# 2  
Old 05-19-2009
How can i do it ?
1. write a sed script which should substitute the text as:

Code:
sed 's/test compare \[property get \[findObject ":dlgGotoLine.lineNumText"\] visible\] true/#&/'


2. find all the text files in the required folders using...
Code:
find . -type f

3. fed the files as input to the sed script, and redirect the output to the original files if need be.

Hope this helps.
# 3  
Old 05-19-2009
Another command to substitute the line:

Code:
sed 's/\(.\)\(.*\)/\1#\2/' file

# 4  
Old 05-19-2009
can i use pipe

So u mean to say that I should use a pipe in between two commands u described . I mean:

find . -type f | sed 's/test compare \[property get \[findObject ":dlgGotoLine.lineNumText"\] visible\] true/#&/

Is it so ? My files are of tickle file type (.tcl). So could you please brief up more.

Quote:
Originally Posted by thegeek
How can i do it ?
1. write a sed script which should substitute the text as:

Code:
sed 's/test compare \[property get \[findObject ":dlgGotoLine.lineNumText"\] visible\] true/#&/'

2. find all the text files in the required folders using...
Code:
find . -type f

3. fed the files as input to the sed script, and redirect the output to the original files if need be.

Hope this helps.
# 5  
Old 05-20-2009
Error does it work all the time

its not working for:
test compare [property get [findObject ":dockBottom.winDebugControl.tabBreakpoints.table"] shown] true

What i did is:
find . -name "*.tcl" | sed 's/test compare \[property get \[findObject ":dockBottom.winDebugControl.tabBreakpoints.table"\] shown\] true/#&/'

Is this correct ? If so its not working. Can u plz correct me...

Thanks

Quote:
Originally Posted by manoj.b
So u mean to say that I should use a pipe in between two commands u described . I mean:

find . -type f | sed 's/test compare \[property get \[findObject ":dlgGotoLine.lineNumText"\] visible\] true/#&/

Is it so ? My files are of tickle file type (.tcl). So could you please brief up more.
# 6  
Old 05-21-2009
It is not working means .. Is there any error displayed .. If the regex is not matching your text, try altering it to match...

You have not followed the mentioned 3rd point correctly .. It could be followed as
Code:
find . -name "*.tcl" -exec sed -i 's/testing/#&/' {} \;

-i to tell sed to edit the file(s)

Got it ??
# 7  
Old 05-21-2009
Hammer & Screwdriver

Sorry . Dont feel bad. But I did not get it. But I found the answer my self.

U just verify is this right ?

find . -name "*.tcl" | xargs perl -pi -e 's/test\ compare\ \[property\ get\ \[findObject \"\:dlgGotoLine\.lineNumText\"\]\ visible\]\ true/#test\ compare\ \[property\ get\ \[findObject \"\:dlgGotoLine\.lineNumText\"\]\ visible\]\ true/g'

This work fine for me and always.... SmilieSmilie Smilie


Thank you. :-)

Quote:
Originally Posted by thegeek
It is not working means .. Is there any error displayed .. If the regex is not matching your text, try altering it to match...

You have not followed the mentioned 3rd point correctly .. It could be followed as
Code:
find . -name "*.tcl" -exec sed -i 's/testing/#&/' {} \;

-i to tell sed to edit the file(s)

Got it ??
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script using awk to find and replace a line, how to ignore comment lines

Hello, I have some code that works more or less. This is called by a make file to adjust some hard-coded definitions in the src code. The script generated some values by looking at some of the src files and then writes those values to specific locations in other files. The awk code is used to... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

2. Shell Programming and Scripting

How to find text and replace next line.?

Have multiple files with the same format and certain text is the same. Have specific text to search for and then need to replace the next line. Can search on the text DEVICE and multiple lines will be found. The line after each DEVICE line has {. Want to replace the line { with {-someadditiontext.... (2 Replies)
Discussion started by: bigdaddywags
2 Replies

3. Shell Programming and Scripting

Search text and replace line next to it

I have a file which requires modification via a shell script. Need to do the following: 0. take input from user for new text. 1. search for a keyword in the file. 2. replace the line next to this to this keyword with user supplied input. for e.g., my file has the following text: (some... (7 Replies)
Discussion started by: chingupt
7 Replies

4. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

comment a line of the patterns is a the beginning of the line

I need to comment the lines starting with pattern "exclude" or "exclude=". If the work exclude comes at any other part, ignore it. Also, ignore, excludes, excluded etc. Ie only comment the line starting with exclude. File contents. exclude exclude= hi I am excluded excludes excludes= ... (9 Replies)
Discussion started by: anil510
9 Replies

6. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

7. UNIX for Dummies Questions & Answers

how to replace this text with comment

test compare shown] Replace this text with #test compare shown] (1 Reply)
Discussion started by: manoj.b
1 Replies

8. UNIX for Dummies Questions & Answers

how to use vi to replace specific line of text only

hi all, i am new bee to Unix. i know how to replace text for range of lines in vi for e.g. replace | with |||| for line 4 through 7 using vi : 4,7s/|/||||/g but i have to replace | with |||| only for line no 4, 7 and 10 using vi only!!! your help will be appreciated! thanks,... (4 Replies)
Discussion started by: pranav.pandya
4 Replies

9. UNIX for Dummies Questions & Answers

how to replace one line in text with several lines

Hi, I need to replace a specific line in a text (eg the line contains the word MYSERVER) with a number of lines (let's say 4) in which the word MYSERVER will be replaced with server1 in the first line server2 in the second line server3 in the 3rd line server4 in the 4th line The original... (1 Reply)
Discussion started by: FunnyCats
1 Replies

10. Shell Programming and Scripting

Need to add a comment line in a text file

Hi I need to add a comment line at the begining of a text file. The scenario is given below. 1. The number of servers that needs to be updated is around 80 2. The location of the text file in all the servers are the same including the file name. 3. The comment has to be added at the very... (2 Replies)
Discussion started by: orakhan
2 Replies
Login or Register to Ask a Question