LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-21-2009, 07:30 AM   #1
niknak
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Rep: Reputation: 0
simple sed replace problem


All

trying to sed an ini file , just a single value and it refuses to edit the value - leaves it as is.

Here is my script:

OLDT="scantime=-1"
NEWT="scantime=5"

chmod 775 /root/path/myfile.ini
cp /root/path/myfile.ini /root/path/myfile.ini.bk
sed "s/$OLDT/$NEWT/" /root/path/myfile.ini.bk > /root/path/myfile.ini

Even if i ditch the variables and hard code the values, same result

If i hard code the value changes to just -1 and 5 , same problem.

What the heck am i doing wrong here?
 
Old 07-21-2009, 07:36 AM   #2
niknak
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Scrap that thought - looks like the process using the ini file is somehow locking it for edits, so i know this much. never saw this issue before though. is there another way to tackle this even if the file is locked (btw, there is no lockfile on the ini)
 
Old 07-21-2009, 07:55 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Really odd. What if you try the -i option of sed to edit the file in place? You can also make a backup copy of the original file if you add a suffix to -i, for example:
Code:
sed -i.bck "s/$OLDT/$NEWT/" /root/path/myfile.ini
 
Old 07-21-2009, 09:11 AM   #4
niknak
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Original Poster
Rep: Reputation: 0
tried that thanks - same issue - also tried various different terms in the same ini file and sed has no effect at all. it is bizarre. are there any know reasons why sed would not run on / edit a file?
 
Old 07-21-2009, 09:27 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Well, if it does not return any error (e.g. Permission Denied) the only explanation is that the regular expression does not match any pattern in the input file. Actually I tried your code and it works for me.
 
Old 07-21-2009, 01:56 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Hello niknak
Quote:
Originally Posted by colucix View Post
Well, if it does not return any error (e.g. Permission Denied) the only explanation is that the regular expression does not match any pattern in the input file. Actually I tried your code and it works for me.
Can you post the conets of the .ini file?

Best

Charles
 
Old 07-21-2009, 09:29 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And a silly guess thrown in ... what are the chances that the '=' in the
file has a different representation in terms of character encoding than
the one in your script?


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using sed to replace string in file umk Debian 12 02-01-2012 09:39 AM
Sed replace string problem. zcrxsir88 Programming 4 02-11-2009 12:48 PM
sed search replace tomerbd1 Linux - General 9 04-10-2008 05:31 AM
How do I replace ' with sed.... @ngelot Linux - Newbie 2 11-02-2007 08:04 PM
Simple sed problem need help Silvermask Linux - Software 2 04-12-2007 02:15 PM


All times are GMT -5. The time now is 10:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration