Solved

sed error

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

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,…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

756 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