Putting Single Quotes in the Output... 
Author Message
 Putting Single Quotes in the Output...

Hmm, okay, I'm stumped.  Playing with updating files I find that
'convdate -n' will give me a epoch answer BUT

 1839  convdate -n `ls -l|awk '{print $6,$7,$8}'`
 1840  convdate -n `ls -l|awk '{print \'$6,$7,$8\'}'`
 1841  convdate -n `ls -l|awk '{print '$6,$7,$8'}'`
 1842  convdate -n `ls -l|awk '{print "'$6,$7,$8'"}'`
 1843  ls -l|awk '{print $6,$7,$8}'
 1844  ls -l|awk '{print "'"$6,$7,$8"'"}'
 1845  echo "'"`ls -l|awk '{print $6,$7,$8}'"'"
 1846  convdate -n "'"`ls -l|awk '{print $6,$7,$8}'"'"
 1847  convdate -n `ls -l|awk '{print $6,$7,$8}'
 1848  convdate -n `ls -l|awk '{print $6,$7,$8}'`
 1849  `ls -l|awk '{print $6,$7,$8}'`
 1850  ls -l|awk '{print $6,$7,$8}'

None of those will work because convdate requires a ' when there's blank
space in the equation.

How do I get it to have an output of something like

'May  8 09:19'

I can figure out the rest, I'm just stumped on this how to have output
with a ' in it without screwing up awk.

Thanks
Dan
--
UNIX - Not just for vestal {*filter*}s anymore
Linux - Choice of a GNU generation



Tue, 05 Mar 2002 03:00:00 GMT  
 Putting Single Quotes in the Output...
This is really a problem of shell quoting, not an AWK problem as such
(and the exact solution may vary between shells).  If you run an external
program file with the -f command-line option (e.g. "nawk -f x.awk", where
the file x.awk contains the line

{print "'"}

), then awk will output an apostrophe just fine.  Here's shell quoting
that will work for the Unix "sh" shell:

nawk 'BEGIN{print "'\''"}'

--%!PS
10 10 scale/M{rmoveto}def/R{rlineto}def 12 45 moveto 0 5 R 4 -1 M 5.5 0 R
currentpoint 3 sub 3 90 0 arcn 0 -6 R 7.54 10.28 M 2.7067 -9.28 R -5.6333
2 setlinewidth 0 R 9.8867 8 M 7 0 R 0 -9 R -6 4 M 0 -4 R stroke showpage
       % Henry Churchyard         http://www.crossmyt.com/hc/



Tue, 05 Mar 2002 03:00:00 GMT  
 Putting Single Quotes in the Output...


Quote:
> Hmm, okay, I'm stumped.  Playing with updating files I find that
> 'convdate -n' will give me a epoch answer BUT

>  1839  convdate -n `ls -l|awk '{print $6,$7,$8}'`
>  1840  convdate -n `ls -l|awk '{print \'$6,$7,$8\'}'`
>  1841  convdate -n `ls -l|awk '{print '$6,$7,$8'}'`
>  1842  convdate -n `ls -l|awk '{print "'$6,$7,$8'"}'`
>  1843  ls -l|awk '{print $6,$7,$8}'
>  1844  ls -l|awk '{print "'"$6,$7,$8"'"}'
>  1845  echo "'"`ls -l|awk '{print $6,$7,$8}'"'"
>  1846  convdate -n "'"`ls -l|awk '{print $6,$7,$8}'"'"
>  1847  convdate -n `ls -l|awk '{print $6,$7,$8}'
>  1848  convdate -n `ls -l|awk '{print $6,$7,$8}'`
>  1849  `ls -l|awk '{print $6,$7,$8}'`
>  1850  ls -l|awk '{print $6,$7,$8}'

> None of those will work because convdate requires a ' when there's
blank
> space in the equation.

> How do I get it to have an output of something like

> 'May  8 09:19'

> I can figure out the rest, I'm just stumped on this how to have output
> with a ' in it without screwing up awk.

You could do:
awk '{ print "\047"$6,$7,$8"\047" }'

/Peter
--
-= Spam safe(?) e-mail address: pez68 at netscape.net =-

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Fri, 08 Mar 2002 03:00:00 GMT  
 Putting Single Quotes in the Output...

Quote:



>> Hmm, okay, I'm stumped.  Playing with updating files I find that
>> 'convdate -n' will give me a epoch answer BUT

>>  1839  convdate -n `ls -l|awk '{print $6,$7,$8}'`
>>  1840  convdate -n `ls -l|awk '{print \'$6,$7,$8\'}'`
>>  1841  convdate -n `ls -l|awk '{print '$6,$7,$8'}'`
>>  1842  convdate -n `ls -l|awk '{print "'$6,$7,$8'"}'`
>>  1843  ls -l|awk '{print $6,$7,$8}'
>>  1844  ls -l|awk '{print "'"$6,$7,$8"'"}'
>>  1845  echo "'"`ls -l|awk '{print $6,$7,$8}'"'"
>>  1846  convdate -n "'"`ls -l|awk '{print $6,$7,$8}'"'"
>>  1847  convdate -n `ls -l|awk '{print $6,$7,$8}'
>>  1848  convdate -n `ls -l|awk '{print $6,$7,$8}'`
>>  1849  `ls -l|awk '{print $6,$7,$8}'`
>>  1850  ls -l|awk '{print $6,$7,$8}'

>> None of those will work because convdate requires a ' when there's
>blank
>> space in the equation.

>> How do I get it to have an output of something like

>> 'May  8 09:19'

>> I can figure out the rest, I'm just stumped on this how to have output
>> with a ' in it without screwing up awk.

>You could do:
>awk '{ print "\047"$6,$7,$8"\047" }'

or

awk 'BEGIN{sq=sprintf("%c", 39)} {print sq $6, $7, $8 sq}'

this assignment technique also works for double quotes.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Fri, 08 Mar 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Putting Single Quotes in the Output...

2. Getting awk (or sed or anything else) to put single quotes into file

3. Putting single quotes inside Prolog strings

4. replace single quote to double quote with an example

5. single-quoted string conversion to triple-quoted string

6. How to print out single quoted columns?

7. gawk win32 binary & single quote invalid char

8. Substituting single quotes from Perl via shell using awk and gsub

9. parsing lines with quoted strings as single fields

10. awk not printing single quotes

11. awk: putting quotes around a field value

12. How can I escape the single quote symbol?

 

 
Powered by phpBB® Forum Software