Commenting a Line In a File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Commenting a Line In a File
# 1  
Old 08-27-2008
Commenting a Line In a File

HI all
I am working on a script, few details are as follows. I have one properties File and one script. The property file contains the JOBID which are to be executed and the Script runs these jobs ONE by ONE. After completing the JOB I need to comment that job in the property File. This is the step where I am getting stucked up.

Also I need to uncomment the Jobs after completion of the script

Note:: The point is that once a job is completed its commented and if say the script fails then it will start from the point where it ended.

Contents are as follows
1. Properties file

EODJOB=6000
EODJOB=6001
EODJOB=6002
EODJOB=1010
EODJOB=1070
EODJOB=1071
EODJOB=6003
EODJOB=6004
EODJOB=6005

2. Script

#! /usr/bin/ksh
# A test to automate the whole EOD

echo "Starting FX Front Office EOD..."

brn_num=$1
set -e on
error.txt 2>&1

rootdir=$PWD
propfile=$rootdir/FX_EOD_JOB.properties

if [ `grep -c "^EODJOB=" $propfile` -gt 0 ]
then
echo "Running the EOD Process"
for i in `grep "^EODJOB=" $propfile | cut -f2 -d"="`
do
#. ./runEod.sh $i $brn_num>> error.txt 2>&1
if [ $# -eq 0 ] #ok execution
then
#############################
Code to comment the Line in Properies file.
Say fist job picked is 6000 so after execution
the Corrsponding job should be commented. Like
#EODJOB=6000

#############################

fi

echo $i Process completed for Branch No:=$brn_num
done
#############################
Code to uncomment all the Jobs in .properties file
#############################
fi




Kindly help with ur valuable information
# 2  
Old 08-27-2008
I would suggest you keep two files instead; one with the original queue and another which lists all completed jobs. Then you can find which ones are still not run by removing all the completed ones from the queue, and if any remain, you run them. If the files are sorted, some things are easier. If you always proceed from the first line to the next, some things are easier still. Commenting out stuff in the queue file seems error-prone and subject to race conditions.
# 3  
Old 08-27-2008
Many thanks for the reply
Will try out that option as well
However Just for my Knowledge.
How can I update a line in UNIX?
# 4  
Old 08-27-2008
Yes, but generally it means re-writing the entire file. Most tools (sed, perl) create a temporary file, and after processing is complete, moves the temp file to the original one.

It's also possible to open files for reading and writing, but in this case, you'll still have to re-write the lines after the change (because you inserted a character). If your lines began with, let's say, a single space, you could replace the space with a # using this technique. Then you could do a read-write in-place, changing the space for the # and without re-writing the file. You can do this in perl or C.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Commenting a line matched with a specific string in a file

Hi, I would like to comment a line that matched a string "sreenivas" in a file without opening it. Thanks in advance. Regards, Sreenivas (3 Replies)
Discussion started by: raosr020
3 Replies

2. Shell Programming and Scripting

Commenting a specific line and inserting a new line after commented line.

Hello All, I have following file contents cat file #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd line=eeeeee #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! I would like to comment line line=eeeeee and insert a new line... (19 Replies)
Discussion started by: manishdivs
19 Replies

3. Shell Programming and Scripting

Commenting lines in a file using SED

Hi, I need to comment the below lines in a file using sed.These are the few lines of the jsp file that need to be commented. if(top.location != location){ top.location.href = location.href; } Using the below command two lines can be commented: if(top.location != location){ ... (9 Replies)
Discussion started by: meetu
9 Replies

4. Shell Programming and Scripting

Commenting lines

Hi can any body pls help me : I have a file Which Content is like following: p3:s1234:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/msglog 2<>/dev/msglog ca:3:respawn:/opt/GoldWing/currentPM/local/critagt > /dev/msglog 2<>/dev/msglog ca:3:respawn:/opt/GoldWing/currentPM/local/startcia.sh... (2 Replies)
Discussion started by: Aditya.Gurgaon
2 Replies

5. Shell Programming and Scripting

Commenting contab from a script

Dear All, I have many cron entries and want to comment a particular cron entry from a script. Ex- Suppose I have the below cron entries: # DO NOT EDIT THIS FILE - edit the master and reinstall. #Cron entries for Jboss server 1 0 23 * * * /usr/bin/echo 0 23 * * * /usr/bin/asdg_count.sh 0 23 *... (5 Replies)
Discussion started by: avishek007
5 Replies

6. Shell Programming and Scripting

Commenting xml file lines

Hi , I have a XML file like this <dependency> <groupId>fr.xxxx.portail.ear</groupId> <artifactId>_xxxEAR</artifactId> <version>1.0.0-20xxxxx.xxxxx-x</version> <type>ear</type> </dependency> I need to comment single/multiple lines from XML file. How can i... (6 Replies)
Discussion started by: scorpio
6 Replies

7. Shell Programming and Scripting

commenting

can we use "---------" for commenting......... (2 Replies)
Discussion started by: simmijaswal
2 Replies

8. Shell Programming and Scripting

Commenting

How can i comment multiple lines in unix ..............shell script. (6 Replies)
Discussion started by: dreams5617
6 Replies

9. UNIX for Dummies Questions & Answers

Commenting lines

How to comment a set of lines in a script? we use # to comment a single line , is there ant other cmd to comment a block? (2 Replies)
Discussion started by: rolex.mp
2 Replies

10. Shell Programming and Scripting

commenting more then 1 line

Hi all, I m new for linux ... but now i will do this continuously. So my question is how to comment more then 1 line i dont wanna put # to each line.. my script is too big... or u can tell me that how can i add # to sellected lines means if i wanna put # from line number 10 to 20 then how... (3 Replies)
Discussion started by: ajayyadavmca
3 Replies
Login or Register to Ask a Question