Comment a line with SED


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comment a line with SED
# 1  
Old 05-26-2010
Comment a line with SED

I have around 25 hosts and each hosts has 4 instance of jboss and 4 different ip attached to it . I need to make some changes to the startup scripts. Any tips appreciated. I have total of 100 instances which bind to 100 different ip address based on instance name.

For example
File1
Code:
START="/usr/local/jboss/bin/run.start -c instance1 -b 10.120.1.1"
STOP="/usr/local/jboss/bin/run.stop -c instance1"

File2
Code:
START="/usr/local/jboss/bin/spcrun.start -c instance2 -b 10.120.1.2"
STOP="/usr/local/jboss/bin/spcrun.stop -c instance2"

I need to change it to the following.Changes are addition of ip to second line,change in path and command

File1
Code:
START="/jboss/bin/run.sh -c instance1 -b 10.120.1.1"
STOP="/jboss/bin/run.sh -c instance1" -b 10.120.1.1

# 2  
Old 05-26-2010
Code:
file=File1
. "$file"
ip=${START##* }
{
printf 'START="%s"\n' "${START#/usr/local}"
printf 'STOP="%s %s"\n' "${STOP#/usr/local}" "$ip"
} > "$file"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to comment a specific line of a file?

Hi, I need to comment out (insert # in the front of a line) a line that has entry Defaults requiretty using command-line as I need to do this on hundreds of servers. From Defaults requiretty To #Defaults requiretty I tried something like below but no luck: Please advise,... (3 Replies)
Discussion started by: prvnrk
3 Replies

2. AIX

Comment out crontab using sed command

I am trying to comment out the crontab entries using sed. I want to comment it out for a particular environment say '/mypath/scripts/'. Using the full path as pattern, it is working. but using variable it is not working. i have tried double quotes too. but no luck! $ crontab -l ... (3 Replies)
Discussion started by: SKhan
3 Replies

3. 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

4. Shell Programming and Scripting

sed adding/removing comment in crontab

I have a requirement where I want to add a comment '#' in my crontab, run a process, than remove the '#' I added. Example cron #5,10 * * * * ls -lt /tmp 10,5 * * * * ls -lt /var I would like to be able use sed or awk to add a '#' at the begining of each line. After the command... (4 Replies)
Discussion started by: BeefStu
4 Replies

5. Shell Programming and Scripting

Using sed to comment out line in /etc/vfstab

I am running a script remotely to do the following 1. Kill all processes by a user 2. Uninstall certain packages 3. FTP over a new file 4. Kill a ldap process that is not allowing my /devdsk/c0t0d0s7 slice to un-mount 5. Unmount /h 6. comment out the slice in vfstab 7. newfs the... (9 Replies)
Discussion started by: deaconf19
9 Replies

6. Shell Programming and Scripting

Help using SED to comment XML elements

I'm trying to write a script to help automate some VERY tedious manual tasks. I have groups of fairly large XML files (~3mb+) that I need to edit. I need to look through the files and parse the XML looking for a certain flag contained in a field. If I find this flag (an integer value) I need... (4 Replies)
Discussion started by: J-Hon
4 Replies

7. Shell Programming and Scripting

get rid of xml comment by grep or sed

Hi, I would like to get rid of all comment in an xml file by grep or sed command: The content seem like this: <!-- ab cd ef gh ij kl --> Anyone can help? Thanks and Regards (3 Replies)
Discussion started by: RonLii
3 Replies

8. UNIX for Dummies Questions & Answers

how to replace a text of line with a comment line

I want to replace this line : "test compare visible] true" and make it "#test compare visible] true". How can I do it ? And it should be checked in many sub folder files also. (6 Replies)
Discussion started by: manoj.b
6 Replies

9. Shell Programming and Scripting

Placing a comment at the beginning of a line

Hello - I am running Linux. I want to place a comment char at the beginning of a line in a file. For example: testvar=`grep username /etc/people sed -e 's/$testvar/#$testvar/g' /etc/people I cannot get the above commands to put a comment at the beginning of the line. Any... (3 Replies)
Discussion started by: mlike
3 Replies

10. Shell Programming and Scripting

sed/awk to insert comment at defined line number

Hi there, may someone easily help me on this : I want to insert a text in a specific line number like : linenumb2start=`cat memory_map.dld | nl -ba | egrep -i "label" | cut -f1` line2insert=`expr $linenumb2start + 2` and now I need to replace something like {} with {comment} at... (8 Replies)
Discussion started by: homefp
8 Replies
Login or Register to Ask a Question