How to use sed command for change special lines?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use sed command for change special lines?
# 1  
Old 01-26-2010
How to use sed command for change special lines?

Hi,

I want to add a character "#" in this few lines with sed command

Initial:
Code:
### CACCIA: DEBUT ###
if $(grep -wqi "$2" /etc/passwd); then
        chuser -R files registry=files $2
fi
### CACCIA: FIN ###

Result with sed command:

Code:
### CACCIA: DEBUT ###
#if $(grep -wqi "$2" /etc/passwd); then
#        chuser -R files registry=files $2
#fi
### CACCIA: FIN ###

Thank you

Last edited by Franklin52; 01-26-2010 at 12:59 PM.. Reason: Please use code tags!
# 2  
Old 01-26-2010
Something like this:
Code:
sed 's/^[^#].*/#&/' file

# 3  
Old 01-26-2010
Or even:
Code:
sed 's/^[^#]/#&/' file

-or-
Code:
sed '/^#/!s/^/#/' file

# 4  
Old 01-26-2010
Code:
awk '!/^#/ {$0="#"$0}1 ' urfile

# 5  
Old 01-27-2010
Hi,

thank you for your reply.
But, i forget to tell that this lines are in a file with other lines.

I have the character "#" in all file.

thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tcsh script - sed command for special characters

Hi, I am using sed command to replace following line in gz file- sed -n 's/""COS_12_TM_1" ( 1101110101001001010011110100000010110100010010000000100000000010XX010000000 )"/""COS_12_TM_1" ( 110111010100100101001111MM00000010110100010010000000100000000010XX010000000 )"/g' filename.gz $x=... (4 Replies)
Discussion started by: Preeti Chandra
4 Replies

2. Shell Programming and Scripting

sed command to add special character (')

I have a file (input) which contains are below. Member Analytics Engine Enterprise Manager Dev Tutorial I want to change contains as below by using sed command 'Member Analytics Engine'; 'Enterprise Manager'; 'Dev Tutorial'; First, I tried to add (') on every first line by using sed... (8 Replies)
Discussion started by: anshu ranjan
8 Replies

3. Shell Programming and Scripting

sed command: change only twice

Hello, I recently sought help on another thread about how to prefix 2 words in a file with 'pack/'. This is the command: sed --in-place 's/"\(libraries\|objects\)"/"pack\/\1"/g' Background: I have a .json file with the word 'libraries' and 'objects' in it. However, 'libraries' occurs twice;... (6 Replies)
Discussion started by: AJ Ruckman
6 Replies

4. UNIX for Dummies Questions & Answers

Using sed to change lines and add them if they don't exist..

I've googled the hell out of this, and in my quest to advance my knowledge and expertise in modifying phones to make them more awesome, I ended up here. I've found answers about patterns and whatnot that seem really complex for what I am trying to do, and basically it is this: if the line says... (2 Replies)
Discussion started by: Silentbtdeadly
2 Replies

5. Shell Programming and Scripting

Format of SED command to change a date

I have a website. I have a directory within it with over a hundred .html files. I need to change a date within every file. I don't have an easy way to find/replace. I need to change 10/31 to 11/30 on every single page at once. I tried the command below but it didn't work. Obviously I don't know... (3 Replies)
Discussion started by: ijustsawmars
3 Replies

6. Shell Programming and Scripting

How to print range of lines using sed when pattern has special character "["

Hi, My input has much more lines, but few of them are below pin(IDF) { direction : input; drc_pinsigtype : signal; pin(SELDIV6) { direction : input; drc_pinsigtype : ... (3 Replies)
Discussion started by: nehashine
3 Replies

7. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

8. Shell Programming and Scripting

SED command to change ./ to a space

Hello, i'm trying to remove the ./ from this file using this SED command: sed 's/.///g' all3.lst > all4.lst Does anyone know the correct format for this? For example, i'm trying to convert ./_ABMSTR.TXT.out to: _ABMSTR.TXT.out Thanks... (11 Replies)
Discussion started by: bobk544
11 Replies

9. Shell Programming and Scripting

sed command to change 2nd field

Hi I am a beginner to sed command, here I have a question about using sed to add a few characters into a token of a string. For example, I have a file, sqw:qqq:123124:uiqe dfd:ccc:12390:dfjis cde:aaa:21311:dfjsid and, I want the output to be, sqw:qqq:123124:uiqe... (4 Replies)
Discussion started by: Julius
4 Replies

10. Shell Programming and Scripting

Sed insert and Change lines help needed

Hi, How can i use insert and change command in ksh shell. I am using : sed -e '1i\TEXTTOBEINSERTED\' FILENAME But there is no effect... Also sed -e 'c\thisischange\' Filename Please Explain how to proceed?? (2 Replies)
Discussion started by: JunkYardWars
2 Replies
Login or Register to Ask a Question