adding a character in front of a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting adding a character in front of a line
# 1  
Old 07-10-2008
adding a character in front of a line

Hi everyon,
I am trying to search for a pattern in a file and add "//" to the begining of the file.
lets say i want to comment out a line from my codes. the line that should be commented out contains the word "reset". i need to search for the word "reset" and comment out that specific line. is there anyone who could help me with this?

Thanks,
# 2  
Old 07-10-2008
Try sed
Code:
sed 's%reset%//&%g' file


Last edited by danmero; 07-10-2008 at 07:59 PM..
# 3  
Old 07-10-2008
Bug

Try these examples:-

// finds 123 and puts 'a' in front of it
bash# echo "123 abc" | sed 's/123/a &/'
a 123 abc

//finds abc and puts 'a' in fron of it
bash# echo "123 abc" | sed 's/abc/a &/'
123 a abc
# 4  
Old 07-11-2008
Hi,

Try this,

Code:
sed '/reset/s%^%//%g'

Regards,
Chella
# 5  
Old 07-11-2008
thanks everyone,
it works just fine now. it was very helpful
# 6  
Old 07-11-2008
I have a similar question, what is i want to comment out that line and also couple of lines above and under that specific line. the reason that i don't use the same method to comment out the other lines is that they contain a similar pattern as some other lines in my code; therefore i need a method to comment out couple of line above and below the specific line
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding a backslash in front of square brackets with sed

I'm trying to convert this line: to \ with sed. This is what I have so far: sed -e 's/\]*\)\]/\\\\\/' but this still gives me . Any suggestions? (15 Replies)
Discussion started by: lehaste
15 Replies

2. Shell Programming and Scripting

Adding end of line character in the last record

Need to add end of line character to last record in a fixed width file. When i take the record length of each line, for all the records it gives example like 200 except the last line as 199. Due to this my other script fails. Please help me on this. (4 Replies)
Discussion started by: Amrutha24
4 Replies

3. Shell Programming and Scripting

Adding new line character

Hi All, i am taking end of records using tail command got the out is "END OF FILE. ROW COUNT: 10" and record count in the file is 3. while append the both data into test2.txt file,it's append like END OF FILE. ROW COUNT: 108 my output should be in the test2.txt file END OF FILE. ROW... (9 Replies)
Discussion started by: bmk
9 Replies

4. Shell Programming and Scripting

Script for adding a word in front of all line in a file

Hi I've one file full of paths of certain files and I want to add some extra file words in front of all the paths. for eg: i have a file name test.txt which show some details only.. 024_hd/044/0344eng.txt 035_bv/222/editor.jpg here I want to add /usr/people/indiana/ infront of all the... (4 Replies)
Discussion started by: ratheeshp
4 Replies

5. Shell Programming and Scripting

Inserting newline in front of multi-character string

I'm working with a large file with multiple records, each record begins with ISA. The issue is, sometimes ISA is at the start of the line, sometimes it's in the middle of the line. So before I can csplit my main file into multiple records, I have to get each record header onto its own line. ... (7 Replies)
Discussion started by: verge
7 Replies

6. Shell Programming and Scripting

How join line and add | in front

Hello, Did any one know how to use perl join line and add | in front Input--> timestamp=2009-11-10-04.55.20.829347; a; b; c; ddaa; timestamp=2009-11-10-04.55.20.829347; aa; bb; cc; Output--> ... (2 Replies)
Discussion started by: happyday
2 Replies

7. Shell Programming and Scripting

Adding a special character at the end of the line

I used following to add * at the end of the line in file1. It adds * at the end but has a space before it for some lines but some other lines it adds exactly after the last character. How do I take out the space ? sed 's/$/*/' file1 > file2 example: contents of file1 : ... (2 Replies)
Discussion started by: pitagi
2 Replies

8. Shell Programming and Scripting

ksh - adding a dynamic value to the front of a line

Hi Forum, Im trying to write some code to read a file, take a certain dynamic value and write it back to the file at the front of every line. For example, file.txt is: SIMPLE=HELLO CONFIDENTIAL=false SENDER=false REQUIRED=true FEEDBACK=false UPDATE=false REQUIRED=false MAPPING=true... (9 Replies)
Discussion started by: ocelot
9 Replies

9. Shell Programming and Scripting

Adding a word in front of a word of each line.

Adding a word in front of a word of each line.In that line only one word will be there. pl help:( (4 Replies)
Discussion started by: Ramesh Vellanki
4 Replies

10. Shell Programming and Scripting

Adding a character in the beginning of every line in a .dat file

How can i add a character(#) in the beginning of every line in a .dat file (2 Replies)
Discussion started by: Cool Coder
2 Replies
Login or Register to Ask a Question