Unix Shell - Replacing single quote with double quote in a line

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2007 > Replacing single quote with double quote in a line





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Replacing single quote with double quote in a line
equation

2007-02-22, 1:18 pm

Hello group,

I am looking for a single sed line for replacing single quote with
double quote in a line.

I prefer a one step process rather than two seds in pipe.

Thanks

Ed Morton

2007-02-23, 1:21 am

equation wrote:
> Hello group,
>
> I am looking for a single sed line for replacing single quote with
> double quote in a line.
>
> I prefer a one step process rather than two seds in pipe.
>
> Thanks
>


sed "s/'/\"/g"
Rainer Weikusat

2007-02-23, 7:21 am

"equation" <equation@techemail.com> writes:
> I am looking for a single sed line for replacing single quote with
> double quote in a line.


tr "'" "\""
Logan Shaw

2007-02-24, 1:23 am

Rainer Weikusat wrote:
> "equation" <equation@techemail.com> writes:
>
> tr "'" "\""


Nice solution. I think it's prettier if you write it this way:

tr "'" '"'

Or this way:

tr ' \"

I guess part of my point is that symmetry is nice.

- Logan
Logan Shaw

2007-02-24, 1:23 am

equation wrote:
> Hello group,
>
> I am looking for a single sed line for replacing single quote with
> double quote in a line.
>
> I prefer a one step process rather than two seds in pipe.


I prefer using a character other than "/" in sed expressions where you
are going to use backslashes. It's tricky for the eye to make sense of
a string that has a bunch of slashes and backslashes in it. So:

sed -e s:':\":g

Or, you can take advantage of the fact that you can quote either type of
quote character with the other type and the fact that you can begin and
stop quoting in the middle of a string:

sed -e s:"'":'"':g

- Logan
Michael Paoli

2007-02-25, 1:25 am

On Feb 22, 6:21 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> equation wrote:
> sed "s/'/\"/g"


Or with one fewer quoting characters:
sed -e s/'/\"/g

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com