Need to comment some code via script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to comment some code via script
# 1  
Old 06-17-2011
Need to comment some code via script

Hi,
I am writing a shell script, which should comment a if-fi loop in a file.
From google i found that, we can use below qualifier to comment a section of code,
:<<COMMENT

COMMENT
But i could not place these keywords before and after if-fi loop.
Any help would be appreciated.
Finally the file should be having like this

:<<COMMENT
if [ "$asdf" = "3" ]; then
----
----
fi
COMMENT
# 2  
Old 06-17-2011
Code:
bash-3.00$ sed -e 's|^if|:<<COMMENT &|' -e 's|^fi|& COMMENT|' test
:<<COMMENT if [ "$asdf" = "3" ]; then
----
----
fi COMMENT
bash-3.00$ cat test
if [ "$asdf" = "3" ]; then
----
----
fi

# 3  
Old 06-17-2011
Quote:
Originally Posted by itkamaraj
Code:
bash-3.00$ sed -e 's|^if|:<<COMMENT &|' -e 's|^fi|& COMMENT|' test
:<<COMMENT if [ "$asdf" = "3" ]; then
----
----
fi COMMENT
bash-3.00$ cat test
if [ "$asdf" = "3" ]; then
----
----
fi


This is replacing all if-fi loops, so i changed the command to,
sed -e 's|^if \[ "$asdf"|:<<COMMENT &|' -e 's|^fi|& COMMENT|'

this is modifying all "fi" statements.

How to change only that particular if-fi loop?

Last edited by successlin; 06-17-2011 at 08:42 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script Comment code blocks in a bash source file

Just began to learn on Shell Script. I got an exercise from my friend. I know how to make this happen in C, but I'm not familiar with Shell Script. Hope I can get some help from all of you. I want to write a bash script to comment code blocks in a bash source file. What I mean comment is '#', I... (1 Reply)
Discussion started by: HiFuture0801
1 Replies

2. Shell Programming and Scripting

Create a file with comment in script

Hello, Be indulgent for my english. Can you help me ? function f1 { } egrep -v '^#' list_file \ | while read arg1 arg2 arg3 arg4; do f1 $arg1 $arg2 $arg3 $arg4 done In list_file there is I want to replace list_file by a $var then when i launch the script with a file's... (13 Replies)
Discussion started by: amazigh42
13 Replies

3. UNIX for Dummies Questions & Answers

Easiest way to comment/uncomment a shell script?

cd path line1 line2 line3 line4 line5 Lets say thats the sample script...So say if i have to comment the above script, which would be the better way so that whenever i want, i cud comment or uncomment the same. Thanks (1 Reply)
Discussion started by: saggiboy10
1 Replies

4. Shell Programming and Scripting

Replacing part of XML code inside comment tags

Hello! I'd like to modify custom values in a XML config file between comment tags using bash script. <feature> <keyboardshortcut>C-m</keyboardshortcut> <option1>disabled</option2> <option2>enabled</option2> </feature> <!-- bash script features START --> <feature> ... (2 Replies)
Discussion started by: prism1
2 Replies

5. Shell Programming and Scripting

add line and remove comment in some script

Hi, i need some help. i am not sure about my idea. I have a script directory under my home directory,which has a lot of scripts in it. These are some names of the scripts in /axxhome/prdv/script aly300.sh axt300.sh arv300.sh clp300.sh ctth300.sh aly400.sh axt400.sh arv400.sh... (6 Replies)
Discussion started by: debu000
6 Replies

6. Shell Programming and Scripting

Comment/Devbug traverser ruby Script

Hello all, i need some help, having never herd of ruby before i joined my workplace im now saddled with alot of scripts written in ruby and i need to find out how to debug certain things (values of array's hashes etc). What i need is how to view each step in this command in a log file: ... (0 Replies)
Discussion started by: limamichelle
0 Replies

7. UNIX for Dummies Questions & Answers

multiline comment in shell script

Is thery any way to give comment to multiple line without explicitly specifying # at the begining of each line ? (2 Replies)
Discussion started by: hiten.r.chauhan
2 Replies

8. UNIX for Dummies Questions & Answers

Why do a unix script starts with a comment?

For eg: #!/usr/bin/ksh <remaining code goes here> .. .. Does the compiler ignores that? Thanks (2 Replies)
Discussion started by: ajincoep
2 Replies

9. Shell Programming and Scripting

Pls comment on my script.

Hi guys, hope you scripting gurus here can help me out, the logic in my script somehow not working the way it should, this script part of a bigger backup script suppose to do some checking on the cluster prior to bringing up the package on MC/SG after backend cloning operation, this portion is... (3 Replies)
Discussion started by: sparcguy
3 Replies

10. Shell Programming and Scripting

Block Comment in Shell script

how to put multiline comments in a shell script like /* Some code */ in C language? (3 Replies)
Discussion started by: skyineyes
3 Replies
Login or Register to Ask a Question