LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxAnswers Discussion
User Name
Password
LinuxAnswers Discussion This forum is to discuss articles posted to LinuxAnswers.

Notices


Reply
  Search this Thread
Old 03-22-2010, 03:09 PM   #1
robiwan
LQ Newbie
 
Registered: Nov 2009
Posts: 1

Rep: Reputation: 0
Shell variables in sed when using paths


A new la entry has been added:

Shell variables in sed when using paths

Quote:
The normal syntax for sed is:

Code:
sed "s/FINDTHIS/REPLACEBYTHIS/"
but when you have a case where REPLACEBYTHIS contains the forward slash character, that syntax will fail.

For example, say that you have a shell variable MY_LOG_PATH=/var/log/here and there is a configuration file containing a setting like

Code:
app.log.path = REALLOGPATH/log.txt
and you want to replace REALLOGPATH by the content of $MY_LOG_PATH.
 
Old 03-22-2010, 06:16 PM   #2
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
You can use nearly any character to delimit the regex and replacement text. A common replacement for / in sed expressions is #, especially when / appears in the pattern or replacement text.
 
Old 11-20-2012, 08:53 AM   #3
Don Johnston
LQ Newbie
 
Registered: Nov 2012
Posts: 7

Rep: Reputation: Disabled
Smile Sed lead character

I have a sed script which reads sed -e 's/@@/\xOA/g' file1 file2. It results in the file being displayed with the change. How can I have it transfer the file file with the replaced characters in place.
 
Old 01-14-2014, 11:35 AM   #4
sajjad008
LQ Newbie
 
Registered: Jan 2014
Posts: 2

Rep: Reputation: Disabled
ok good
 
Old 08-16-2016, 05:54 PM   #5
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
Quote:
Originally Posted by Don Johnston View Post
I have a sed script which reads sed -e 's/@@/\xOA/g' file1 file2. It results in the file being displayed with the change. How can I have it transfer the file file with the replaced characters in place.

sed '...' file1 > file2
 
Old 08-16-2016, 07:24 PM   #6
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Depending on your version of sed and how portable it needs to be use sed -i ... the '-i' switch stands for in place see the sed manpage for further details.
 
  


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
How to use multiple paths in configure env variables radam Linux - Software 5 04-07-2016 12:22 PM
Executable paths and environment variables - troubles the_darkside_986 Programming 8 02-21-2007 10:07 PM
SED and shell variables 3saul Linux - Software 4 12-28-2005 11:37 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
Shell paths Manny88 Linux - General 3 09-25-2003 09:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxAnswers Discussion

All times are GMT -5. The time now is 07:39 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
Open Source Consulting | Domain Registration