problems escaping chars 
Author Message
 problems escaping chars


>I have a file with two columns and want output like this:

>TEXT 'COL1' text = COL2

>So I have:

>awk '{print "TEXT \'" $1 "' text = " $2}' file > file.out

>which gives:

>TEXT \ text = COL2

>I have verified that $1 is acutally a value, and numerous other things
>tell me that the problem is with my method of escpaing.  I need the '
>in  there.  Escaping the second one gives me an error, as does putting
>spaces in between the single and double quotes.  What am I doing wrong?

>Thanks very much.

Try setting up some string constants to use them in your program that
represent the characters
I use them as constants instead of as the escaped character directly because
it's easier to remember what the code is


So in your code, this would be:

awk 'BEGIN {SING_QUOTE="\047"} {print "TEXT " SING_QUOTE $1 SING_QUOTE "
text = " $2}' file > file.out

or to avoid using constants, try:

awk '{print "TEXT \047" $1 "\047 text = " $2}' file > file.out

Not tested in this code, but I've used this before and it worked.


Sun, 01 Apr 2001 03:00:00 GMT  
 problems escaping chars


>awk '{print "TEXT \047" $1 "\047 text = " $2}' file > file.out

Concatenating multiple strings isn't efficient since concatenation is a
binary operation. In the example above awk would perform 3 separate
concatenations. Using printf is more efficient for combining multiple
strings. Try

awk '{ printf("TEXT %c%s%c text = %s\n", 047, $1, 047, $2) }' file >

Sun, 01 Apr 2001 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Expect script changing telnet escape using `set escape ^\` problem

2. How NOT to interpret backslashes to escape chars.

3. CreateVrmlFromString escape char

4. send escape char with telnet

5. Can't escape special chars in regex.match

6. avoiding escaping chars in exec commands

7. Escape codes / printing a document with embedded escape codes

8. How to escape escape?

9. Word-wrapping problem with 8-bit strings (latin1 accented chars) and other related problems

10. Object comment do: [:char | char yourself]

11. reversing lines char by char, but not the line order in a file

12. Problem with escape characters and [g]sub


Powered by phpBB® Forum Software