sed edit in place -i issues


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed edit in place -i issues
# 1  
Old 11-04-2009
sed edit in place -i issues

Hello,

I am attempting to create a command that I can eventually put into a loop so I can edit 1file on many servers. I would like to edit the file in place with sed -i. If not I will take any suggestions on how to use a temp file. I need to remove a email address from the configuration file below.


O/S=rhel4
Shell=bash

File Location:
Code:
filename1=/var/log/swatch/.swatchrc.apache

Original File:
Code:
[root@radio1 swatch]# cat .swatchrc.apache 
watchfor /File size limit exceeded/
throttle 10:00,key=$7
mail=arup.error@intertechmedia.com logswatch@intertechmedia.com, subject=Apache Error File size limit occured

Desired File:
Code:
[root@radio1 swatch]# cat .swatchrc.apache 
watchfor /File size limit exceeded/
throttle 10:00,key=$7
mail=logswatch@intertechmedia.com, subject=Apache Error File size limit occured

My Attempt:
Code:
[root@radio1 swatch]# cat .swatchrc.apache | sed  's/arup.error@intertechmedia.com //'g
watchfor /File size limit exceeded/
throttle 10:00,key=$7
mail=logswatch@intertechmedia.com, subject=Apache Error File size limit occured
[root@radio1 swatch]#

My attempt works, however when I try with the -i flag in sed I get the following:
Code:
[root@radio1 swatch]# cat .swatchrc.messages | sed -i 's/arup.error@intertechmedia.com //'g
sed: can't read -: No such file or directory
[root@radio1 swatch]#

I think the issue may be related to the configuration file having a . in front.

Regards,
abacus

Last edited by abacus; 11-04-2009 at 10:25 AM.. Reason: I am sure I also qualify for UUOC
# 2  
Old 11-04-2009
Quote:
Originally Posted by abacus
I am sure I also qualify for UUOC
You are! Smilie

Try this but make a backup first of the original file:

Code:
sed 's/arup.error@intertechmedia.com //g' .swatchrc.apache > tempfile && mv tempfile .swatchrc.apache

Regards
# 3  
Old 11-04-2009
Thanks fo your time.

Upon executing It appeared that it would work. I was asked to overwrite file. However no dice. Still has the email address that I wanted to remove. Also is there a way to place a yes in there. So I will not get asked again? There will be many files to edit.

Code:
[root@radio5 bin]# sed 's/arup@intertechmedia.com //g' /var/log/swatch/.swatchrc.apache > tempfile && mv tempfile /var/log/swatch/.swatchrc.apache 
mv: overwrite `/var/log/swatch/.swatchrc.apache'? y
[root@radio5 bin]# cd /var/log/swatch/                 
[root@radio5 swatch]# cat .swatchrc.apache 
watchfor /File size limit exceeded/
throttle 10:00,key=$7
mail=arup.error@intertechmedia.com logswatch@intertechmedia.com, subject=Apache Error File size limit occured

I am reading man pages now, as well as searching google.

abacus
# 4  
Old 11-04-2009
It works fine for me with the given sample file.
Do you get the desired output on the screen if you don't redirect it to a file?

To disable the prompt before overwriting of the the mv command, use the -f option.
# 5  
Old 11-04-2009
Operator Error,

As in my fault. Everything is working perfect. Thanks for your time in this matter.

Abacus
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

File manipulation place 0 before the number using sed

I'm new with sed, and i am really confused with slashes, backslashes, parentheses, I've tried reading some beginner's guide, but still trouble fixing this problem, do you have any tips where or what to read to learn more about sed? can you also help me with my problem? Note: I was tasked to use... (4 Replies)
Discussion started by: akopocpoypoy
4 Replies

2. Shell Programming and Scripting

awk pattern matching in place of sed

I have written a script to parse data from some files on a Solaris 10 system and send the output to a CSV formatted file. The code snipped i am using to pull the data is as follows.... src_line=$(sed -n "/^search_pattern$/{=;}" $file) for i in $src_line do start_line1=$(( i + 9 )) nawk -v... (4 Replies)
Discussion started by: electricheadx
4 Replies

3. Shell Programming and Scripting

edit sed command

how can i make this sed command run faster? sed '51000000,51347442!d' file and sed '51347442,$ !d' file File is a 9GB in size. it runs on sunos 5.10 and linux red hat 6 servers and i use bash. (5 Replies)
Discussion started by: SkySmart
5 Replies

4. Shell Programming and Scripting

Place digit in front of the line searching pattern using sed command

hi All, i want to add the single digit front of the line in the report file and string compare with pattern file. patter file: pattern1.txt pattern num like 4 love 3 john 2 report file: report.txt i like very much but john is good boy i will love u so after execute... (9 Replies)
Discussion started by: krbala1985
9 Replies

5. Shell Programming and Scripting

How to get awk to edit in place and join all lines in text file

Hi, I lack the utter fundamentals on how to craft an awk script. I have hundreds of text files that were mangled by .doc format so all the lines are broken up so I need to join all of the lines of text into a single line. Normally I use vim command "ggVGJ" to join all lines but with so many... (3 Replies)
Discussion started by: n00ti
3 Replies

6. Shell Programming and Scripting

SED: Place char at starting and replace selected line

Hello Experts, I am working on a small file editing script. Since all experts here are very generous to give me the complete code, I would take up the problem in steps so that I ensure my opportunity to learn. AIM: The script has some commented and some uncommented lines. I need to : ... (2 Replies)
Discussion started by: hkansal
2 Replies

7. Shell Programming and Scripting

SED command help: Can we pass predefined variables in place of regex

Hi All, I have a doubt. Can we assign a regular expression for pattern searching to a variable in a script and then use that variable in place of a regular expression in sed command.I tried but got some syntax error!!Is it not possible.Because my requirement is that i have a generic script to get... (8 Replies)
Discussion started by: usha rao
8 Replies

8. Shell Programming and Scripting

ksh - truncate a log in place, sed -i not available captain!

Hi there:) Because of security requirements, It would be much better if I could truncate my logs in place using sed -i (or ?). I cant use the -i option on sed in my environment. Can anyone help a DBA? (5 Replies)
Discussion started by: quigley007
5 Replies

9. Shell Programming and Scripting

Edit a large file in place

:confused:Folks, I have a file with 50 million records having 2 columns. I have to do the below: 1. Generate some random numbers of a fixed length. 2. Replace the second column of randomly chosen rows with the random numbers. I tried using a little bit of perl to generate random numbers... (6 Replies)
Discussion started by: mvijayv
6 Replies

10. Shell Programming and Scripting

Simple SED edit

I have output like the following: B D 20070116095820001 N D S0000579.LOG S0000582.LOG B D 20070116095750001 N D S0000574.LOG S0000576.LOG B D 20070116095734001 N D S0000570.LOG S0000573.LOG B D 20070116095705001 N D S0000569.LOG S0000569.LOG B D ... (5 Replies)
Discussion started by: rdudejr
5 Replies
Login or Register to Ask a Question