The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular Expressions ramky79 UNIX for Advanced & Expert Users 3 05-21-2008 02:13 PM
Help with regular expressions arushunter Shell Programming and Scripting 13 12-23-2006 08:31 PM
regular expressions jack1981 Shell Programming and Scripting 4 07-12-2006 12:10 PM
regular expressions in c++ szzz High Level Programming 2 10-06-2003 07:33 AM
Regular Expressions AresMedia Shell Programming and Scripting 1 08-22-2002 12:55 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-10-2002
Registered User
 

Join Date: Feb 2002
Location: Sydney, Australia
Posts: 3
Question Regular expressions in sed

I'm using sed to alter a parameter file used in another process. Basically, the file is a template containing a few variables which need to be replaced at runtime.

The problem is that using sed with filenames that contain the / character causes matches to fail.

eg:
fileName=/mnt/someinputfile
sed -e "s/param1/${fileName}/g" somefile.txt > runfile

Could someone suggest how I can get around this?

Also, anyone know a good site for regexp?

=====================================
I've also tried doing an escaped forward slash substitution. ie. replace all "/" with "\\\/". It works outside the shell, but not inside. Wierd.

Here's the code fragment:

Code:
# 2 Modify the runCSjob.xml file: output to jobFile
subRunDate=`echo ${runDate}|sed -e "s/\//\\\\\//g"`;
substituteRunDate="1,\$s/\\\${runDate}/${subRunDate}/g";
subOutputFile=`echo ${outputFile}|sed -e "s/\//\\\\\//g"`;
substituteOutputFile="1,\\\$s/\${outputFile}/${subOutputFile}/g"
substituteRunType="1,\$s/\${runType}/${runType}/g";
sed -e "${substituteRunDate}" -e "${substituteOutputFile}" -e "${substituteRunType}" ${UTOPIA_BIN}/runCSjob.xml > ${tmpFile}.xml
Ideas??
__________________
:)
Mark

Last edited by mfreemantle; 02-10-2002 at 06:21 PM.
Forum Sponsor
  #2 (permalink)  
Old 02-10-2002
killerserv's Avatar
Unix Predator
 

Join Date: Dec 2000
Location: Phoenix, AZ
Posts: 670
mfreemantle,
You may try to post this question in
Quote:
UNIX Shell Programming and Scripting Q & A
im sure someone in that forum could help with that question.
  #3 (permalink)  
Old 02-10-2002
Registered User
 

Join Date: Sep 2001
Location: Green Bay, WI
Posts: 66
if your parameter has a / in it, append a \ before it an sed will perform the proper search & replace
  #4 (permalink)  
Old 02-11-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,454
Re: Regular expressions in sed

Quote:
Originally posted by mfreemantle

The problem is that using sed with filenames that contain the / character causes matches to fail.

eg:
fileName=/mnt/someinputfile
sed -e "s/param1/${fileName}/g" somefile.txt > runfile


Ideas??
Try:
sed -e "s=param1=${fileName}=g" somefile.txt > runfile

Sed's s command does not require the use of a slash as a delimiter. You can use any character. Pick a character that is not in your data.
Google The UNIX and Linux Forums
Closed Thread

Tags
regex, regular expressions

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0