how to add ' using awk | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

how to add ' using awk

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-06-2007
icemantj icemantj is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 6 August 2007, 10:58 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
how to add ' using awk

hi all

I would like to find out how to add ' using awk. I have used the \ to hide the special character but still not successful.

The error stated,
Syntax error at line 1 : `"' is not matched.

My command is,
awk '{print "\'", $1 ;}' lotnums.txt > 1.txt


Pls advise.
Sponsored Links
    #2  
Old 08-06-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
 
Join Date: Apr 2002
Last Activity: 20 December 2009, 10:56 AM EST
Location: Italy
Posts: 370
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
echo "test" | awk -v v="'" '{ print v $1 v; }'

Output:
'test'

Sponsored Links
    #3  
Old 08-06-2007
icemantj icemantj is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 6 August 2007, 10:58 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Is there any reason why we can't use \'

Hi

Is there any reason why \' does not work in awk whereas \" is able to be accepted?

Pls advise. Thanks
    #4  
Old 08-06-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 17 April 2014, 8:28 AM EDT
Location: NM
Posts: 10,057
Thanks: 250
Thanked 756 Times in 711 Posts
Because the shell is getting in the way and thinks the ' is the end of the awk program.
Sponsored Links
    #5  
Old 08-06-2007
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
 
Join Date: Feb 2006
Last Activity: 9 April 2014, 6:05 AM EDT
Location: Almerķa, Spain
Posts: 755
Thanks: 23
Thanked 106 Times in 101 Posts
Check this tricky variant:

Code:
echo "test" | awk  '{ print "'\''"$1"'\''"}'

Sponsored Links
    #6  
Old 08-06-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 7 November 2013, 6:42 AM EST
Posts: 2,651
Thanks: 0
Thanked 16 Times in 16 Posts

Code:
# awk 'BEGIN{print "\047"}'
'

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -4. The time now is 02:27 PM.