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: 21 November 2014, 12:22 PM EST
Location: NM
Posts: 10,278
Thanks: 287
Thanked 814 Times in 756 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: 3 November 2014, 3:12 AM EST
Location: Almerķa, Spain
Posts: 777
Thanks: 24
Thanked 110 Times in 105 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: 9 November 2014, 12:24 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 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 03:04 PM.