LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-19-2007, 03:04 AM   #1
ShaqDiesel
Member
 
Registered: Jul 2005
Posts: 144

Rep: Reputation: 15
sed error


hello, in a ksh script I have
sed "s/\/\([a-ZA-z]*\)/[[$str\/\1]]/g"
where $str was a string stored earlier in this kornshell script.

For example, the script stored "cheese" in $str. Then it would substitute /Burger with [[cheese/Burger]]. However I get a "sed statement not closed" error. What's wrong with my syntax? Thanks in advance.

Last edited by ShaqDiesel; 01-19-2007 at 03:12 AM.
 
Old 01-19-2007, 03:14 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Maybe you didn't give all the info needed, 'cause the following seems to work:
Code:
#!/bin/ksh

str="cheese"

sed "s/\/\([a-ZA-z]*\)/[[$str\/\1]]/g" infile
Example run:
Code:
$ cat infile
/burger

$ ./tets
[[cheese/burger]]
-----------------------------------
I tested this on SUN hardware with solaris 9. In general solaris is less forgiving then linux, in this case it is the opposite. The [a-ZA-z] part will not work with linux, it does with solaris. Sorry for the confusion.

Last edited by druuna; 01-19-2007 at 01:39 PM. Reason: Explanation added why this (seems to) work.
 
Old 01-19-2007, 03:45 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
The problem is [a-ZA-z], which should be [a-zA-Z]. Think of ranges of character as their ASCII values. Saying [a-z] is like saying (pseudocode):
Code:
if ( char >= ascii('a') && char <= ascii('z') ...
Plugging in the ASCII values, saying [a-Z] would work out as:
Code:
if ( char >= 97 && char <= 90 ) ...
which you should be able to see doesn't make sense - it can never be true. The regexp engine checks for apparent errors like this, and gives an error when it finds one.
 
Old 01-19-2007, 12:12 PM   #4
ShaqDiesel
Member
 
Registered: Jul 2005
Posts: 144

Original Poster
Rep: Reputation: 15
thanks, I can't believe I didn't catch that. My problem now is that it doesn't interpret $str as a variable, but a literal; my result is [[$str/burger]] instead of [[cheese/burger]]; how do I fix this?
 
Old 01-19-2007, 12:18 PM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Which quotes are you using around the sed statement: single or double? It should be double quotes, as shown in the example in my previous post.

If that is not the case, could you post the code you are using so we can have a look?
 
  


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
sed error : Unknown option to 's' powah Linux - General 4 01-04-2012 02:52 PM
'sed: command garbled:' error on Solaris fatjack Solaris / OpenSolaris 3 08-25-2006 05:15 PM
sed error message:extra characters after the command wmh830621 Programming 4 08-14-2006 07:13 PM
sed -f: error nano_mag Linux - Newbie 3 05-15-2005 07:51 PM
sed substitution error BlkPoohba Programming 1 08-25-2004 02:00 PM

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

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