How can I execute an equivalent of `head -z` when I don't have the `-z` option available?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite
1












I need head -z for a script (off-topic, but the motivation can be found in this question), but in my CoreOS 835.13.0 I get head: invalid option -- 'z'.



Full head --help output:



Usage: head [OPTION]... [FILE]...
Print the first 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=[-]K print the first K bytes of each file;
with the leading '-', print all but the last
K bytes of each file
-n, --lines=[-]K print the first K lines instead of the first 10;
with the leading '-', print all but the last
K lines of each file
-q, --quiet, --silent never print headers giving file names
-v, --verbose always print headers giving file names
--help display this help and exit
--version output version information and exit

K may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report head translation bugs to <http://translationproject.org/team/>
For complete documentation, run: info coreutils 'head invocation'


The funny part is that the last line tells me to run info coreutils 'head invocation' but I get info: command not found.










share|improve this question

























    up vote
    3
    down vote

    favorite
    1












    I need head -z for a script (off-topic, but the motivation can be found in this question), but in my CoreOS 835.13.0 I get head: invalid option -- 'z'.



    Full head --help output:



    Usage: head [OPTION]... [FILE]...
    Print the first 10 lines of each FILE to standard output.
    With more than one FILE, precede each with a header giving the file name.
    With no FILE, or when FILE is -, read standard input.

    Mandatory arguments to long options are mandatory for short options too.
    -c, --bytes=[-]K print the first K bytes of each file;
    with the leading '-', print all but the last
    K bytes of each file
    -n, --lines=[-]K print the first K lines instead of the first 10;
    with the leading '-', print all but the last
    K lines of each file
    -q, --quiet, --silent never print headers giving file names
    -v, --verbose always print headers giving file names
    --help display this help and exit
    --version output version information and exit

    K may have a multiplier suffix:
    b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
    GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

    GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
    Report head translation bugs to <http://translationproject.org/team/>
    For complete documentation, run: info coreutils 'head invocation'


    The funny part is that the last line tells me to run info coreutils 'head invocation' but I get info: command not found.










    share|improve this question























      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      I need head -z for a script (off-topic, but the motivation can be found in this question), but in my CoreOS 835.13.0 I get head: invalid option -- 'z'.



      Full head --help output:



      Usage: head [OPTION]... [FILE]...
      Print the first 10 lines of each FILE to standard output.
      With more than one FILE, precede each with a header giving the file name.
      With no FILE, or when FILE is -, read standard input.

      Mandatory arguments to long options are mandatory for short options too.
      -c, --bytes=[-]K print the first K bytes of each file;
      with the leading '-', print all but the last
      K bytes of each file
      -n, --lines=[-]K print the first K lines instead of the first 10;
      with the leading '-', print all but the last
      K lines of each file
      -q, --quiet, --silent never print headers giving file names
      -v, --verbose always print headers giving file names
      --help display this help and exit
      --version output version information and exit

      K may have a multiplier suffix:
      b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
      GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

      GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
      Report head translation bugs to <http://translationproject.org/team/>
      For complete documentation, run: info coreutils 'head invocation'


      The funny part is that the last line tells me to run info coreutils 'head invocation' but I get info: command not found.










      share|improve this question













      I need head -z for a script (off-topic, but the motivation can be found in this question), but in my CoreOS 835.13.0 I get head: invalid option -- 'z'.



      Full head --help output:



      Usage: head [OPTION]... [FILE]...
      Print the first 10 lines of each FILE to standard output.
      With more than one FILE, precede each with a header giving the file name.
      With no FILE, or when FILE is -, read standard input.

      Mandatory arguments to long options are mandatory for short options too.
      -c, --bytes=[-]K print the first K bytes of each file;
      with the leading '-', print all but the last
      K bytes of each file
      -n, --lines=[-]K print the first K lines instead of the first 10;
      with the leading '-', print all but the last
      K lines of each file
      -q, --quiet, --silent never print headers giving file names
      -v, --verbose always print headers giving file names
      --help display this help and exit
      --version output version information and exit

      K may have a multiplier suffix:
      b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
      GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

      GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
      Report head translation bugs to <http://translationproject.org/team/>
      For complete documentation, run: info coreutils 'head invocation'


      The funny part is that the last line tells me to run info coreutils 'head invocation' but I get info: command not found.







      coreutils head coreos






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 5 at 15:57









      Pedro A

      1163




      1163




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote













          Swap NULs and NLs before and after head:



          <file tr 'n' 'n' | head | tr 'n' 'n'


          With recent versions of GNU sed:



          sed -z 10q


          With GNU awk:



          gawk -v RS='' -v ORS='' 'print; NR == 10 exit'





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f467066%2fhow-can-i-execute-an-equivalent-of-head-z-when-i-dont-have-the-z-option-a%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote













            Swap NULs and NLs before and after head:



            <file tr 'n' 'n' | head | tr 'n' 'n'


            With recent versions of GNU sed:



            sed -z 10q


            With GNU awk:



            gawk -v RS='' -v ORS='' 'print; NR == 10 exit'





            share|improve this answer
























              up vote
              4
              down vote













              Swap NULs and NLs before and after head:



              <file tr 'n' 'n' | head | tr 'n' 'n'


              With recent versions of GNU sed:



              sed -z 10q


              With GNU awk:



              gawk -v RS='' -v ORS='' 'print; NR == 10 exit'





              share|improve this answer






















                up vote
                4
                down vote










                up vote
                4
                down vote









                Swap NULs and NLs before and after head:



                <file tr 'n' 'n' | head | tr 'n' 'n'


                With recent versions of GNU sed:



                sed -z 10q


                With GNU awk:



                gawk -v RS='' -v ORS='' 'print; NR == 10 exit'





                share|improve this answer












                Swap NULs and NLs before and after head:



                <file tr 'n' 'n' | head | tr 'n' 'n'


                With recent versions of GNU sed:



                sed -z 10q


                With GNU awk:



                gawk -v RS='' -v ORS='' 'print; NR == 10 exit'






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 5 at 16:26









                Stéphane Chazelas

                286k53528866




                286k53528866



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f467066%2fhow-can-i-execute-an-equivalent-of-head-z-when-i-dont-have-the-z-option-a%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?