0

I tried gsub() but it didn't work. Here is the command:

awk -v a="'"  b=" \" "  "gsub(a,b,$0){print $0}" D:\re.json

or anybody could tell me what is the right escape character in Windows command line?

1 Answers1

1

As suggested, put the script into a file. Referring to Windows, we would understand the context to be Windows batch-files (rather than say, mingw which has its own problems with command-line scripting). For Windows batch files

  • double-quotes are eaten before the program sees them
  • there is no well-documented way to escape double-quotes
  • single-quotes are passed as-is to the program (and are not, as in Bourne shell, used for quoting).

Here are a few links where those issues are discussed:

So the rules are entirely different from what awk needs for this construction. The last link by the way gives some clues that you might use to devise a workaround (at the expense of readability). It is also discussed in Escaping Double Quotes in Batch Script.

As a separate file, the script would also be more readable, e.g., call that foo.awk:

gsub("'"," \" ",$0){print $0}

and use it as

awk -f foo.awk D:\re.json
Community
  • 1
  • 1
Thomas Dickey
  • 43,185
  • 7
  • 51
  • 88
  • No need to write `{print $0}` or to provide the` $0` arg or `gsub()` - that's the default behavior. The whole script would just be `gsub(/'/," \" ")`. I also changed the delimiters for the first arg for gsub() since it is an RE, not a string - won't change the behavior in this case but will in others so a good habit to get into. – Ed Morton Apr 01 '15 at 14:04
  • I changed the question's script minimally to show the effect of the quoting alone. If it were something to recommend, I would show the way a `^`-escaped workaround would look as well -- but the result would be hard to read and not reusable. – Thomas Dickey Apr 02 '15 at 08:10