0

I can't find a way to redirect the output of GnuWin32's tr to a file:

(dev) go|w:\srv> dkversion . | jq .vcs | tr -d \" > vcs.txt
tr: extra operand `>'
Try `tr --help' for more information.
Error: writing output failed: Invalid argument

The dkversion . | jq .vcs command outputs "svn", so to reproduce it with a simpler testcase:

(dev) go|w:\srv> echo "svn"
"svn"

(dev) go|w:\srv> echo "svn" | tr -d \"
svn

(dev) go|w:\srv> echo "svn" | tr -d \" > vcs.txt
tr: extra operand `>'
Try `tr --help' for more information.

on linux echo '"svn"' | tr -d '"' > foo.txt works, so I'm guessing the problem has to do with the quoting of the "..? I haven't been able to figure out what the correct syntax would be though..

thebjorn
  • 26,297
  • 11
  • 96
  • 138
  • You might want to try redirection before options: `tr >vcs.txt -d \"` – CiaPan Oct 05 '15 at 14:51
  • @CiaPan that works! Make it into an answer and I'll give you points :-) – thebjorn Oct 05 '15 at 14:57
  • I don't care much about points :) although it's nice to get them. Anyway I make an answer just to complete the 'Q&A' routine. – CiaPan Oct 05 '15 at 15:01
  • Alas the trick works for redirecting to a file only. It will not work if you need to pipe results to another command – if you put options after the piping metasymbol, they become the other command's options. :-( – CiaPan Oct 06 '15 at 06:51

1 Answers1

1

Put redirection before options:

tr > vcs.txt -d \"
CiaPan
  • 9,381
  • 2
  • 21
  • 35