Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sed problem with single quote

Status
Not open for further replies.

parbhani

Technical User
Jul 3, 2002
125
GB
Hi all ,

I want to put a single quote at the begining and single quote plus a comma at the end of each line in a file. I did the following ,

sed -e "s/^/'/" -e "s/$/',/" filename

It worked.
But if I do ,

sed -e 's/^/\'/' -e 's/$/\',/' filename

That do not work, I am given a secondary prompt by the shell as if the command is not complete.

Why \' is not working like this ?

Regards
 
It is a good habit to choose a delimiter for the substitute string that is no being used in the substitution itself. And not just for sed. It applies to vi, awk, and unix commands such as tr, grep, etc.

Sometimes the grass is greener on the other side because there is more manure there - original.
 
From man ksh...
Each of the metacharacters has a special meaning to the shell. A character can be quoted (i.e., made to stand for itself) by preceding it with a \. All characters enclosed between a pair of single quote marks (''), are quoted. A single quote cannot appear within single quotes. Inside double quote marks (""), parameter and command substitution occurs and \ quotes the characters \, `, ", and $.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top