Problem in sed using double quotes and single quotes

Problem in sed using double quotes and single quotes

Post by Sanjiv K. Bhati » Sat, 09 Jun 2001 11:22:19



I am trying to append a line using sed and get different results using
double quotes and single quotes.  I want to change the part being appended
to shell variables and hence, need to use double quotes.  This is what I
get:

$ cat foo
Doe, John:12.34:10
Smith, Mary:12.45:11
Bush, Jerry:13.10:9
$ sed '/Smith/a\

Quote:> Bob, Billy:12.10:13
> ' foo

Doe, John:12.34:10
Smith, Mary:12.45:11
Bob, Billy:12.10:13
Bush, Jerry:13.10:9
$ sed "/Smith/a\
Quote:> Bob, Billy:12.10:13
> " foo

sed: Extra text at end of command: /Smith/aBob, Billy:12.10:13
$

Can someone please help?  I am using Korn shell on Solaris and have tried it
under Korn shell on HP/UX as well.  I get the same result.

Sanjiv

 
 
 

Problem in sed using double quotes and single quotes

Post by Chris F.A. Johnso » Sat, 09 Jun 2001 13:00:35



> I am trying to append a line using sed and get different results using
> double quotes and single quotes.  I want to change the part being appended
> to shell variables and hence, need to use double quotes.  This is what I
> get:

> $ cat foo
> Doe, John:12.34:10
> Smith, Mary:12.45:11
> Bush, Jerry:13.10:9
> $ sed '/Smith/a\
> > Bob, Billy:12.10:13
> > ' foo
> Doe, John:12.34:10
> Smith, Mary:12.45:11
> Bob, Billy:12.10:13
> Bush, Jerry:13.10:9
> $ sed "/Smith/a\
> > Bob, Billy:12.10:13
> > " foo
> sed: Extra text at end of command: /Smith/aBob, Billy:12.10:13
> $

> Can someone please help?  I am using Korn shell on Solaris and have tried it
> under Korn shell on HP/UX as well.  I get the same result.

Is this what you want?

x="Smith"
y="Bob, Billy:12.10:13"
sed '/'$x'/a\
'"$y"'
' foo

--

        =================================================================



 
 
 

Problem in sed using double quotes and single quotes

Post by Cyrille Lefevr » Sun, 10 Jun 2001 14:02:52



> I am trying to append a line using sed and get different results using
> double quotes and single quotes.  I want to change the part being appended
> to shell variables and hence, need to use double quotes.  This is what I
> get:

> sed: Extra text at end of command: /Smith/aBob, Billy:12.10:13
> $

your problem is ' vs. ".

$ echo 'a\

Quote:> b'

a\
b
$ echo "a\
Quote:> b"

ab
$ echo "a\\
Quote:> b"

a\
b

so, using ", what you what is double \\, not single \ :

$ sed "/Smith/a\\

Quote:> Bob, Billy:12.10:13
> " foo

Cyrille.
--


Supprimer "%no-spam" et ".invalid" pour me repondre. | about who it chooses
Remove "%no-spam" and ".invalid" to answer me back.  | to be friends with.
 
 
 

1. REGULAR EXPRESSIONS; PERL/AWK/SED; SINGLE QUOTES/DOUBLE QUOTES

Hi,

I am trying to look for the string

.uk,|/|end-of-string

this regular expression can be constructed as follows:

'\.uk,|/|$'

Now, suppose I stick the text uk into a variable called $suffix.
I can no longer use single quotes, because I destroy the meaning of
$suffix. If I use double quotes, though, then i Destroy the special
meaning of the metacharacter $.

"\.$suffix,|/|$"

Help!

Never mind,

I wound up using "\.$suffix"',|/|$', but this problem is so persistent
and pervasive in awk, csh, sed, and even perl that I wonder if there
are better-documented solutions.

Also, what is csh's equivalent of the \b,\w,\s constructs in perl?

Sent via Deja.com http://www.deja.com/
Before you buy.

2. A consistent kernel crash error

3. replace single quote to double quote with an example

4. TCP works but UDP, ICMP doesn't

5. ? about single quote-double quote

6. How do I change my IP address?

7. replace single quote to double quote with an example

8. Apache bug: referer/agent entries in transfer log

9. Double quotes within double quotes (no apostrophes)

10. replace single quote by escaped single quote

11. Q: sh: Can I quote '"' in a double quoted string?

12. What is the difference between single and double quotes?

13. Single/double quotes in shell ?