Menu

Need Windows format output from grep (CRLF)

Help
2008-03-06
2012-07-26
  • PixelPusher

    PixelPusher - 2008-03-06

    Hi,
    I need to get the output of the grep command to be in DOS format (using CRLF instead of LF). There's an easy way to do this, right?

    Thanks!

    WinXP SP2 and Win2K SP5

    C:\Program Files\GnuWin32\bin>grep --version
    grep (GNU grep) 2.5.1

    Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

     
    • GnuWin

      GnuWin - 2008-03-06

      Filter grep's output through unix2dos (from CygUtils: http://gnuwin32.sourceforge.net/packages/cygutils.htm)

       
    • PixelPusher

      PixelPusher - 2008-03-06

      Hmmm... isn't it possible to do this with just the GnuWin32 utilities? Perhaps using "tr"? The whole reason I'm trying to use the GnuWin32 version of grep is to get rid of reliance on cygwin stuff.

      Thanks for the idea, though.

      Thom

       
      • GnuWin

        GnuWin - 2008-03-06

        But dos2unix is a GnuWin32 port. It is not dependent on Cygwin. Cygutils is a collection of utilities so called because originally they were intended to be useful for Cygwin. However, most of them, such as dos2unix, can be, and on Gnuwin32 have been, ported to native MS-Windows.

         
        • PixelPusher

          PixelPusher - 2008-03-06

          Ah, yes... I realized that after posting my previous note. So, unix2dos it is. (Though I was really hoping for a grep commandline option to change the output format. Oh, well.)

          Thanks again.
          Thom

           
          • Keith Marshall

            Keith Marshall - 2008-03-07

            Ok, I'm playing devil's advocate here, but shouldn't the output from a native port of grep be CRLF anyway? Why would any tool, intended for processing text files and compiled natively on Woe32, explicitly force stdout to _O_BINARY mode, (which would be required to achieve LF, rather than CRLF output)?

            IMO, (which probably doesn't count for much here, since I use the MSYS ports of tools such as grep, and I expect them to force _O_BINARY mode anyway), this could be considered a bug in the GnuWin32 port.

            This said, the -U' (a.k.a.--binary') option may be helpful in your case; see http://man.linuxquestions.org/?query=grep&section=0&type=2 for details.

            Regards,
            Keith.

             
            • Adam A. Koch

              Adam A. Koch - 2008-07-16

              I concur.

               
            • GnuWin

              GnuWin - 2008-07-23

              I've (finally) looked into this. It appears that this behavior is by design, so actually it is a feature. Basically grep behaves in this way because it can also grep binary files (this ìs advertised as an option and a possible use of grep), for which conversion to CRLF would be inappropriate. In general, I'm not in favor of changing behavior that is by design; instead one should address the maintainer. The one possibility I see for such a request would be a combination of the -a (--text) option with CRLF conversion, since then the user explicitly requests all files to be viewed as text files, and so all output might be regarded as text output.
              In the port of grep-2.5.3, I will for the time being implement this combination of --text and CRLF output, provided no-one objects, beforehand or later.

               
MongoDB Logo MongoDB