Solved

sed error

Posted on 2006-11-28
6
545 Views
Last Modified: 2012-05-05
This is driving me nuts - especially since it worked as an alias. I've tried to simplify the command in .bashrc :

81 function phpfind {
82         #find $MROOT -name "*.php" | sed "s/\/var\/www\/proteanit.net\/docs\/moodle/\$M/" | xargs egrep
83         find $MROOT -name "*.php" | sed -e "s/v/x/"
84 }

but this is the error i'm getting. Why?

sed: -e expression #1, char 46: unknown option to `s'


0
Comment
Question by:CEHJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 35

Accepted Solution

by:
Duncan Roe earned 100 total points
ID: 18031311
Use another separator than "/" in the sed command. Did you miss a backslash after "moodle" by any chance? Also shell strips a level of backslashes before sed gets to see the command line - that's the difference between an alias and a shell script BTW. Usually yoe see sed's -e program in single quotes to avoid that, but of course you want parameter substitution. Maybe:

  find $MROOT -name "*.php" | sed "s%/var/www/proteanit.net/docs/moodle%$M%" | xargs egrep
0
 
LVL 86

Author Comment

by:CEHJ
ID: 18031647
Actually i'm beginning to confuse myself - i think i;m getting tired. What i really intended do was to run that send command if the argument of -l goes to sed, so i suppose it should come after egrep and before the last argument to egrep, but only if i wanted an -l type result. Ugh. Better come back to this tomorrow maybe ;-)
0
 
LVL 2

Assisted Solution

by:ctwaley
ctwaley earned 100 total points
ID: 18033069
Line 83 doesn't have 46 characters (char 46) in the sed expression, only 6 chars, so it must refer to the one in line 82.

In line 82, the 46th character the error is referring to is the final forward slash, right before the closing double quote.  In otherwords, there is a total of 46 characters in the whole sed expression in line 82, which means the shell script is not stripping the backslashes between the double quotes.  About the only thing the shell does inside double quotes is parameter expansion.  The other exception is to replace octal (\###) or hex (\x##) numbers with their ascii equivalent, and to allow special escape sequences, such as \b for backspace, \n for newline, \t for a tab, etc..  Almost all other characters are left alone and do nothing special (even single quotes inside double quotes are only single quotes)........

But, as duncan_roe points out, use a different character instead of a forward slash right after the 's' at the start of the expression......It's much less confusing that way, and easier to read........It also might be the cause of the error, in a roundabout way.......Although the forward slashes in the path name have all been escaped from your example above, it might have something to do with the parameter expansion with "$M", such as a forward slash in the variable's replacement value (ie., see if there is a forward slash in the variable's replacement value)..........

Also, another tip is to escape the dot with a backslash in the regexp part of the expression (proteanit\.net).........In this particular case it might not make a difference, but a single dot in a regexp is equivalent to the '?' wildcard in a filename expansion, which is to replace it with any single character.........It's just a good habit to get into, whether or not it makes a difference in the expression.......However, the backslash is not required in the substition part of the expression for the '$M' (as in duncan_roe's example)......

One more thing, are you sure the expression in the phpfind function is exactly the same as what was in the alias?.......I'm sure you already doubled-checked that, but I had to ask anyway.... :-)

0
 
LVL 86

Author Comment

by:CEHJ
ID: 18034913
Great comments folks. I meant to say

'What i really intended do was to run that sed command if the argument of -l goes to sed'

so i'm going to have to rethink this
0
 
LVL 86

Author Comment

by:CEHJ
ID: 18284952
Thanks for the comments
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question