Solved

sed error

Posted on 2006-11-28
6
538 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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,…
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 …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

744 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

13 Experts available now in Live!

Get 1:1 Help Now