LinuxQuestions.org
Visit Jeremy's Blog.
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 11-03-2014, 08:55 AM   #1
rhellinuxsa
LQ Newbie
 
Registered: Oct 2014
Posts: 3

Rep: Reputation: Disabled
Angry Using sed to replace commented paths


Hi i want to replace a content in a file that contains in a file that starts with '#' if '#' is not there also replace a the respective path.

for eg:
# this is a general for giving the path
#/var/log
replace it by removing the '#' and puting the path like
/var/sumo
if '#' is not there also replace it with
/var/sumo
using sed command.


kindly help as its very urgent
 
Old 11-03-2014, 09:17 AM   #2
Habitual
LQ 5k Club
 
Registered: Jan 2011
Location: Nowhere near you, thank God.
Distribution: OSX Sierra
Posts: 8,570
Blog Entries: 14

Rep: Reputation: Disabled
http://goo.gl/q4YvfV

What's urgent is you need to not use urgent in your subject titles as indicated on every "new Thread"...
Code:
Subject:

Bad: "Help Me!!" or "URGENT"
Good: "Why is my mouse pointer wrong?"
Best: "Mouse pointer distorted on XFree86 4.3 with Geforce FX 5200"
We're all volunteers here.

Lack of searching on your part does not constitute an Urgency on our part.

Last edited by Habitual; 11-03-2014 at 09:20 AM.
 
Old 11-03-2014, 10:09 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,711
Blog Entries: 12

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
Quote:
Originally Posted by rhellinuxsa View Post
Hi i want to replace a content in a file that contains in a file that starts with '#' if '#' is not there also replace a the respective path.

for eg:
# this is a general for giving the path
#/var/log
replace it by removing the '#' and puting the path like
/var/sumo
if '#' is not there also replace it with
/var/sumo
using sed command.


kindly help as its very urgent
You seem to know pretty much what you want to do, and also the correct system call to perform that action with, "sed".

Why don't you post what you have tried rather than "kindly help as its very urgent"

Unless the instructor has already collected papers ... in that case just wait for the review tomorrow in class. (Provided you attend)
 
Old 11-03-2014, 10:44 AM   #4
rhellinuxsa
LQ Newbie
 
Registered: Oct 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi All,
Thanks for the reply,sorry for the using words like that next time it wont be done. By the By i am not able to do it using sed and i have tried using sed i am not able to do it kindly help me ..


Thanks,
Rhellinuxsa
 
Old 11-03-2014, 12:11 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,711
Blog Entries: 12

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
Quote:
Originally Posted by rhellinuxsa View Post
Hi All,
Thanks for the reply,sorry for the using words like that next time it wont be done. By the By i am not able to do it using sed and i have tried using sed i am not able to do it kindly help me ..


Thanks,
Rhellinuxsa
Once again: "Please post what you have tried" You should place all code within: [code][/code] tags.

If you use used the advanced editor available the # sign up top allows you to place code tags around selected text.
 
Old 11-03-2014, 11:35 PM   #6
eklavya
Member
 
Registered: Mar 2013
Posts: 619

Rep: Reputation: 136Reputation: 136
If you want every line which has text '/var/log' should be uncommented as well as '/var/log' should be replaced with /var/sumo.
Code:
sed -e 's|^#\(.*\)/var/log|\1/var/sumo|g' -e 's|/var/log|/var/sumo|g' filename
 
  


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
Shell variables in sed when using paths robiwan LinuxAnswers Discussion 5 08-16-2016 07:24 PM
[SOLVED] How to replace text using sed or awk in a file without changing the commented text coolpraz Programming 4 01-03-2013 06:19 AM
[SOLVED] Sed replace Help replace for (<a> guessity Linux - Newbie 1 11-18-2011 09:05 AM
How do I replace ' with sed.... @ngelot Linux - Newbie 2 11-02-2007 07:04 PM
Sed - suitable to replace CR LF? J_Szucs Programming 3 05-12-2003 06:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:36 PM.

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