Add Comments to the specifi lines i na file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Add Comments to the specifi lines i na file
# 1  
Old 09-21-2008
Add Comments to the specifi lines i na file

I have a requirement like below.I need to Comment some lines in a file.

File contains following information.

{
attribute1
attribute2
atrribute3
attribute4
attribute5
attribute6
attribute7
}

I have a requirement like some times i need to comment lines 3 to before '}' and some times from 5 to before '}'

Out Put for scenario1
{
attribute1
attribute2
//atrribute3
//attribute4
//attribute5
//attribute6
//attribute7
}

Out Put for schenario2
{
attribute1
attribute2
atrribute3
attribute4
//attribute5
//attribute6
//attribute7
}

Can any one please help me how can i acheive this.

Thanks
# 2  
Old 09-21-2008
Code:
sed -e '/attribute3/,/attribute7/ s/.*/\/\/&/ ' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

2. Shell Programming and Scripting

Grep last two lines, calc & adding comments

....... 06/09/2013|12:00:00 PM|3|26112|40|44032|27419.7|6 1 0 93 |6|1|0|93 06/09/2013|12:30:00 PM|3|26112|40|44032|27491|11 4 0 85 |11|4|0|85 I have "sysperf.out" file containing the lines above. What I like to have on the output is: Node: prod1db ===> this is the hostname Date:... (7 Replies)
Discussion started by: Daniel Gate
7 Replies

3. Shell Programming and Scripting

Remove comments from file with specific file name extensions

Hello Unix board community, I have to program a shell script, but I am a complete noob so I hope I get some help here. The assignment is as follows: The program removes all comments regardless of formatting or language from files with specific file name extensions (php, css, js, ...).... (3 Replies)
Discussion started by: TheZeusMan
3 Replies

4. Shell Programming and Scripting

Extract some lines from one file and add those lines to current file

hi, i have two files. file1.sh echo "unix" echo "linux" file2.sh echo "unix linux forums" now the output i need is $./file2.sh unix linux forums (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

5. Shell Programming and Scripting

Deleting comments from c-file

hii all, i am writing a shell script to remove comments from a .c/.cpp file. i have written script as the above script file deletes line between /* and */ also lines starting with //. but the problems are : 1) i dont want to delete the content between /** and */. 2)sed -i... (16 Replies)
Discussion started by: yashwantkumar
16 Replies

6. UNIX for Dummies Questions & Answers

Remove blank lines and comments from text file

Hi, I am using BASH. How can I remove any lines in a text file that are either blank or begin with a # (ie. comments)? Thanks in advance. Mike (3 Replies)
Discussion started by: msb65
3 Replies

7. Shell Programming and Scripting

Sed script, changing all C-comments to C++-comments

I must write a script to change all C++ like comments: // this is a comment to this one /* this is a comment */ How to do it by sed? With file: #include <cstdio> using namespace std; //one // two int main() { printf("Example"); // three }//four the result should be: (2 Replies)
Discussion started by: black_hawk
2 Replies

8. UNIX for Dummies Questions & Answers

Delete Comments in file

How can I delete comments (lines beginning with /* and ending with */) in file? with single command line..My suggestion is to use grep and sed! (4 Replies)
Discussion started by: aadi_uni
4 Replies

9. Shell Programming and Scripting

removing comments from file

I'm doing manual way to add and remove "#" on etc/services. Is there anyway I can modify the file using awk or sed or any other program. I use vi to modify /etc/services for enabling telnet , the problem is I don't know how to do it automatically in script. production state: #telnet ... (9 Replies)
Discussion started by: skully
9 Replies

10. UNIX for Dummies Questions & Answers

How to put the comments to 50 lines, using vi editor?

Hi All, Please let me know how I can put a comment (e.g // or #) to more than 50 lines using vi editor in a .cpp/.sh file. Thanks in advance. (3 Replies)
Discussion started by: artikulkarni
3 Replies
Login or Register to Ask a Question