The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
escaping single quote javeed7 Shell Programming and Scripting 3 04-02-2008 05:36 AM
single quote dreams5617 Shell Programming and Scripting 2 12-01-2007 03:37 AM
single or double quote in SED asami Shell Programming and Scripting 2 07-17-2006 03:03 AM
AWK handling of single quote braindrain Shell Programming and Scripting 3 04-27-2006 04:57 PM
Replacing a single quote rjsha1 Shell Programming and Scripting 3 12-23-2005 10:55 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-16-2006
gauravgoel gauravgoel is offline
Registered User
  
 

Join Date: Dec 2005
Location: India
Posts: 218
how to print single quote in awk

Hi all,

It is a very stupid problem but I am not able to find a solution to it.

I am using awk to get a column from a file and I want to get the output field in between single quotes. For example,

Input.txt

123 abc
321 ddff
433 dfg
........

I want output file to be as
output.txt

value is 'abc'
value is 'ddff'
value is 'dfg'
...............

the problem is how to get these single quotes in output, at this moment I am first taking *abc* and then replacing * with ' (single quote).
How can we do this with awk

thanks
Gaurav
  #2 (permalink)  
Old 03-16-2006
hugow hugow is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 15
Show the awk syntax you are using as part of the script and the input data.
  #3 (permalink)  
Old 03-16-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,115
Code:
nawk -v q="'" '{print q $2 q}' Input.txt
  #4 (permalink)  
Old 03-16-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,402
Or use the ascii value...
Code:
awk '{print "\x27" $2 "\x27"}'
  #5 (permalink)  
Old 03-17-2006
gauravgoel gauravgoel is offline
Registered User
  
 

Join Date: Dec 2005
Location: India
Posts: 218
Hi All,
vgersh and ygor thanks a lot for the help, both the above things are working perfectly fine.

Hugow thanks a lot for your time, the awk syntax which I will be using now is

Quote:
awk -v q="'" '{print "value is" q $2 q}' inputfile
or
Quote:
awk '{print "value is \x27" $2 "\x27"}' inputfile
Thanks and regards,
Gaurav
  #6 (permalink)  
Old 10-16-2007
bobdesinger bobdesinger is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 1
a remarkable sequence of quote characters

awk '{ print "value is '"'"'" $2 "'"'"'" }' input.txt

which prints

value is 'abc'
value is 'ddff'
value is 'dfg'
  #7 (permalink)  
Old 08-20-2008
protargol protargol is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 1
easier way

awk '{ print "value is","'\''" $2 "'\''" }' input.txt

does the same thing but may be easier to understand
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 12:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0