LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-01-2007, 02:18 PM   #1
Elguapo
Member
 
Registered: Mar 2005
Distribution: FC7
Posts: 42

Rep: Reputation: 15
sed Issues


I am writing a simple bash script that will be used to run cron jobs that will manipulate various files with in our file structure. The script is extremely simple but I can't seem to figure out one issue.

When I run the script I get this error. sed: -e expression #1, char 6: unknown option to `s'

Here is the script. The issue I am having is that I am trying to replace . with / in my second argument I am passing to the script.
#!/bin/sh

cfInstance=$1
callto=`echo $2 | sed -e 's/.///g'`
cfMethod=$3
url=$cfInstance$callto$cfMethod

echo $url
 
Old 06-01-2007, 02:26 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
You're going to need to escape both special characters.

i.e.
Code:
[hector@troy ~]$ cat test-file 
Hi. How are you?

[hector@troy ~]$ sed 's/\./\//g' test-file 
Hi/ How are you?
 
Old 06-01-2007, 02:39 PM   #3
Elguapo
Member
 
Registered: Mar 2005
Distribution: FC7
Posts: 42

Original Poster
Rep: Reputation: 15
Thank you anomie it worked like a charm.
 
Old 06-01-2007, 02:41 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
also, note that you do not have to use "/" as the delimiter. In sed, the delimiter is always the first character after the "s"
so you can do--e.g.:

sed 's*\.*/*g'
(slightly more readable)
 
  


Reply



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
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
awk and sed issues alaios Linux - General 11 03-24-2005 05:33 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:16 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