Solved

sed error

Posted on 2006-11-28
6
539 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
  • 3
6 Comments
 
LVL 34

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Apache application gives "Forbidden" message 5 45
Install MySQL 5.6 and PHP on Centos Linux 6 101
linux ssh 4 59
nagios 4 php error after installation 6 78
Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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.

896 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now