How to copy and comment out


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to copy and comment out
# 1  
Old 06-18-2008
How to copy and comment out

I need help with a script. Here's what I want to do.

I have a file "upsrk.txt" which can be either under "/home/upsrk" OR "/home/oracle"

On some systems file "upsrk.txt" may not exist, in that case I want to just exit out of the script.

If the file is there, I want to check if I have the permissions to write to this file (on some systems it may be owned by root)

If I have the permissions to this file, then I want to look for "upsrk@gmail.com" and then comment the line which contains it.

Thanks in Advance for your Help.
# 2  
Old 06-19-2008
Won't write the whole script for you.
Re the comment out, you can use:
Code:
sed  's/\(.*upsrk@gmail.com.*\)/#\1/' filename

To check if file exist you can use if [ -f "${FILENAME}" ] .
# 3  
Old 06-19-2008
More generally, the test command (aka opening square bracket [ command) has a number of operators for checking file permissions. test -w file checks if you have write access, test -d file checks if it's a directory, etc.
# 4  
Old 06-19-2008
Thank Ynir and era

I am new to the script, would greatly appreciate if you can tell how to put all of this together in a script.

Thanks Again for your help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help about comment verification

Hello, I have a file, in which line 40 is commented. It is basically a cron job, #05,35,50 * * * * /usr/local/scripts/my.sh how i can i verify the line 40 is commented, if not then give me message not commented, otherwise provide us message it is commented. (5 Replies)
Discussion started by: learnbash
5 Replies

2. Shell Programming and Scripting

Need to insert a comment string

I need to insert a comment string to a couple of fields for every line in the file. Different comment string for each field. In below file, fields 7 and 8 "R","1","t0000684","","10/31/2013","10/31/2013","","","","750.23"... (6 Replies)
Discussion started by: Melah Gindi
6 Replies

3. Web Development

cannot execute copy comment but can do echo

I have set the sh file to chmod 755 i only able to print the output but cannot execute the copy why? Below is the code for sh file echo "Hello" cp hello.sh helloworld.sh Below is my code for php. <html> <head> </head> <body> <?php echo '<p>Hello</>'; ?> <?php shell_exec('sh... (4 Replies)
Discussion started by: zhengkoon8
4 Replies

4. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: successlin
2 Replies

5. Shell Programming and Scripting

Comment based on a condition

I want to comment 2 lines based on a condition. If THEN occurs immediately after WHEN then i have to comment both the lunes For example : $cat file1.txt CASE WHEN THEN 1 WHEN c1= 'I' AND c2= '0' THEN 2 So in this example i want to... (2 Replies)
Discussion started by: ashwin3086
2 Replies

6. UNIX for Dummies Questions & Answers

comment lines

Is there a command to put a comment (#) in a whole part of a shell script? (5 Replies)
Discussion started by: vero_81
5 Replies

7. Shell Programming and Scripting

Comment/uncomment a cron

Hi, My requirement is to comment/uncomment a cron job through a script. 1. Redirected the output of crontab -l to a text file. crontab -l >cronoutput.txt 2. grep to find the script running and sed to place the comment (#) as the first char grep -i 'weblogicmonitor.sh'... (5 Replies)
Discussion started by: mannepalli
5 Replies

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

9. Shell Programming and Scripting

Variable for User Comment

SCO 5.06 Is there a variable that holds a user's comment? In scoadmin -account, there's a comment field which we normally populate with the user's name. Or ... am I better off greping /etc/passwd? Thanks! (2 Replies)
Discussion started by: gseyforth
2 Replies

10. UNIX for Dummies Questions & Answers

# comment

Hi guys and Gals AIX 5.1 If I had a # above several scripts would it comment out everything below it? Like this # 01 2 ** ..................................... 02 31 ......................................... # this is a script 03 12 **.......................... Would... (6 Replies)
Discussion started by: rocker40
6 Replies
Login or Register to Ask a Question