The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Add single quotes in string mrjunsy UNIX for Dummies Questions & Answers 1 07-18-2008 11:09 AM
Double quotes or single quotes when using ssh? password636 Shell Programming and Scripting 3 05-29-2008 09:52 PM
awk to print ' (single quotes) orahi001 UNIX for Dummies Questions & Answers 2 03-11-2008 04:30 PM
echo using single quotes chella Shell Programming and Scripting 3 10-29-2007 12:54 AM
Filename containing Single Quotes phani Shell Programming and Scripting 6 03-30-2005 07:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-02-2009
tostay2003 tostay2003 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 23
single quotes in awk statement

Hi,

I have written a code to modify a string say,


Code:
StringA=abc,def,ghi

I need to change it to something like:


Code:
StringB=This means abc='ABC', This mean def='DEF', This means ghi= 'GHI'


Code:
StringB=$(echo $StringA | awk -F',' 'BEGIN { OFS="," } { for (i=1; i<=NF;i++) $i="This means "$i"='ABC'")) THEN '' ELSE " $1 ; print $0 }')

I am not able to print the single quotes to the output or rather assign to String B
  #2 (permalink)  
Old 01-02-2009
Rhije Rhije is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 103
If I understand you correctly, you just need to escape the single quotes that you are wanting to print.

echo 'This is a \'test\''
  #3 (permalink)  
Old 01-02-2009
tostay2003 tostay2003 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 23
Sorry i forgot to put that in my earlier example. I did use the \ to escape the single quotes, but it doesn't work

Code:
StringB=$(echo $StringA | awk -F',' 'BEGIN { OFS="," } { for (i=1; i<=NF;i++) $i="This means "$i"=\'ABC\'")) THEN '' ELSE " $1 ; print $0 }')

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 08:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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