Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

how to add ' using awk

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 08-06-2007
robotronic's Unix or Linux Image
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 Unix and Linux 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 Unix and Linux 08-06-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 28 August 2015, 12:38 PM EDT
Location: NM
Posts: 10,529
Thanks: 353
Thanked 880 Times in 818 Posts
Because the shell is getting in the way and thinks the ' is the end of the awk program.
Sponsored Links
    #5  
Old Unix and Linux 08-06-2007
Klashxx's Unix or Linux Image
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
 
Join Date: Feb 2006
Last Activity: 24 July 2015, 7:39 AM EDT
Location: Almerķa, Spain
Posts: 779
Thanks: 24
Thanked 112 Times in 106 Posts
Check this tricky variant:

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

Sponsored Links
    #6  
Old Unix and Linux 08-06-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 Posts

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

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -4. The time now is 05:22 AM.