LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
LinkBack Search this Thread
Old 07-19-2013, 04:58 AM   #1
sras
Member
 
Registered: Jul 2013
Posts: 31

Rep: Reputation: Disabled
Insert a single quote in a string


Hello Guys,

How to insert a single quote(') in a line using sed command?

source string is: MQRQUE
Target is: 'MQRQUE'

when I run the below command, control is going to the next line, seems command is incomplete.

> echo "MQRQUE"|sed 's/MQRQUE/\'MQRQUE\'/g'
>>


thanks.
 
Old 07-19-2013, 05:29 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,000

Rep: Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003
echo MQRQUE | sed "s/MQRQUE/'MQRQUE'/g"
 
1 members found this post helpful.
Old 07-19-2013, 05:30 AM   #3
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,435
Blog Entries: 11

Rep: Reputation: 181Reputation: 181
I cant explain the behaviour sed which i find kind of akward but I have solution
Code:
sed "s/MQRQUE/'MQRQUE'/g" /tmp/test
Just enclose the sed expression with double ?colons? (dunno the right name here).

to slow

Last edited by zhjim; 07-19-2013 at 05:30 AM. Reason: to slow
 
1 members found this post helpful.
Old 07-19-2013, 05:35 AM   #4
sras
Member
 
Registered: Jul 2013
Posts: 31

Original Poster
Rep: Reputation: Disabled
Smile

Thanks Guys. It worked exactly.
 
Old 07-19-2013, 07:52 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Quote:
Originally Posted by zhjim View Post
Just enclose the sed expression with double ?colons? (dunno the right name here).
Their common name is (straight) double quotes.
 
1 members found this post helpful.
Old 07-19-2013, 09:24 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
The usual terms are single and double quotes, or in shell scripting hard and soft, due to the differences in their behavior.

The way to understand it is that single quotes escape everything up to the next single quote (like a toggle), while double quotes do the same, except that they do not escape "$", "`", and "\" ("!" history expansion is also allowed in interactive sessions). This allows variable and command substitution to occur inside them, and they can still be escaped when needed.

Notice that the two quotation marks themselves are not treated specially. This means that double quotes escape single quotes, and single quotes escape double quotes. That's why pan64's solution works (the single quotes are escaped by the doubles), while the original doesn't work because backslashes don't function inside single quotes.

See the QUOTING section of the bash man page for a more detailed description.

Read these links too for more on how the shell handles arguments and whitespace:
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Get value in single quote sandeep_hello Linux - Software 3 01-18-2013 08:57 AM
How to use Vi to match a string of text, add a new line, insert string... Slycraft Linux - Newbie 7 07-20-2012 10:24 AM
[SOLVED] How to pass a single quote inside of a single quote... trist007 Linux - Newbie 2 02-09-2011 07:07 PM
insert a single quote is text file with sed eln01 Programming 7 05-10-2007 11:02 AM
Insert a quote into your message harisethuraman Linux - Software 0 02-12-2004 09:04 AM


All times are GMT -5. The time now is 09:41 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration