Any way to have a “verbose mode” or “debug mode” with sed?

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












6















Is there a way to make gnu sed be verbose about what is run and what is done ?

I'd like to have something like a "debug mode" so that I can see - for each line of input - the content of the hold space and pattern space before and after the script is run etc.










share|improve this question
























  • Is l;x;l;x; at the start & end of the program adequate?

    – Michael Homer
    Jan 6 at 19:36






  • 1





    It looks like GNU sed gained a --debug feature last summer (version 4.6).

    – fra-san
    Jan 6 at 19:56















6















Is there a way to make gnu sed be verbose about what is run and what is done ?

I'd like to have something like a "debug mode" so that I can see - for each line of input - the content of the hold space and pattern space before and after the script is run etc.










share|improve this question
























  • Is l;x;l;x; at the start & end of the program adequate?

    – Michael Homer
    Jan 6 at 19:36






  • 1





    It looks like GNU sed gained a --debug feature last summer (version 4.6).

    – fra-san
    Jan 6 at 19:56













6












6








6








Is there a way to make gnu sed be verbose about what is run and what is done ?

I'd like to have something like a "debug mode" so that I can see - for each line of input - the content of the hold space and pattern space before and after the script is run etc.










share|improve this question
















Is there a way to make gnu sed be verbose about what is run and what is done ?

I'd like to have something like a "debug mode" so that I can see - for each line of input - the content of the hold space and pattern space before and after the script is run etc.







sed debugging gnu






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 6 at 20:14









Jeff Schaller

39.7k1054126




39.7k1054126










asked Jan 6 at 19:19









don_crisstidon_crissti

50.3k15134162




50.3k15134162












  • Is l;x;l;x; at the start & end of the program adequate?

    – Michael Homer
    Jan 6 at 19:36






  • 1





    It looks like GNU sed gained a --debug feature last summer (version 4.6).

    – fra-san
    Jan 6 at 19:56

















  • Is l;x;l;x; at the start & end of the program adequate?

    – Michael Homer
    Jan 6 at 19:36






  • 1





    It looks like GNU sed gained a --debug feature last summer (version 4.6).

    – fra-san
    Jan 6 at 19:56
















Is l;x;l;x; at the start & end of the program adequate?

– Michael Homer
Jan 6 at 19:36





Is l;x;l;x; at the start & end of the program adequate?

– Michael Homer
Jan 6 at 19:36




1




1





It looks like GNU sed gained a --debug feature last summer (version 4.6).

– fra-san
Jan 6 at 19:56





It looks like GNU sed gained a --debug feature last summer (version 4.6).

– fra-san
Jan 6 at 19:56










1 Answer
1






active

oldest

votes


















5














As fra-san mentioned, GNU sed introduced a --debug option which does pretty much what you’re looking for, in version 4.6; so e.g if you run:



printf '%sn' one two | sed --debug 'H;1h;$x;$s/n/_/g'


the output is



SED PROGRAM:
H
1 h
$ x
$ s/n/_/g
INPUT: 'STDIN' line 1
PATTERN: one
COMMAND: H
HOLD: none
COMMAND: 1 h
HOLD: one
COMMAND: $ x
COMMAND: $ s/n/_/g
END-OF-CYCLE:
one
INPUT: 'STDIN' line 2
PATTERN: two
COMMAND: H
HOLD: onentwo
COMMAND: 1 h
COMMAND: $ x
PATTERN: onentwo
HOLD: two
COMMAND: $ s/n/_/g
MATCHED REGEX REGISTERS
regex[0] = 3-4 '
'
PATTERN: one_two
END-OF-CYCLE:
one_two


I don’t know what distribution you use, but it’s not available yet in Debian, Ubuntu, or Fedora; it will be included in the next releases of Debian (10) and Ubuntu (19.04).






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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    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%2f492871%2fany-way-to-have-a-verbose-mode-or-debug-mode-with-sed%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    As fra-san mentioned, GNU sed introduced a --debug option which does pretty much what you’re looking for, in version 4.6; so e.g if you run:



    printf '%sn' one two | sed --debug 'H;1h;$x;$s/n/_/g'


    the output is



    SED PROGRAM:
    H
    1 h
    $ x
    $ s/n/_/g
    INPUT: 'STDIN' line 1
    PATTERN: one
    COMMAND: H
    HOLD: none
    COMMAND: 1 h
    HOLD: one
    COMMAND: $ x
    COMMAND: $ s/n/_/g
    END-OF-CYCLE:
    one
    INPUT: 'STDIN' line 2
    PATTERN: two
    COMMAND: H
    HOLD: onentwo
    COMMAND: 1 h
    COMMAND: $ x
    PATTERN: onentwo
    HOLD: two
    COMMAND: $ s/n/_/g
    MATCHED REGEX REGISTERS
    regex[0] = 3-4 '
    '
    PATTERN: one_two
    END-OF-CYCLE:
    one_two


    I don’t know what distribution you use, but it’s not available yet in Debian, Ubuntu, or Fedora; it will be included in the next releases of Debian (10) and Ubuntu (19.04).






    share|improve this answer





























      5














      As fra-san mentioned, GNU sed introduced a --debug option which does pretty much what you’re looking for, in version 4.6; so e.g if you run:



      printf '%sn' one two | sed --debug 'H;1h;$x;$s/n/_/g'


      the output is



      SED PROGRAM:
      H
      1 h
      $ x
      $ s/n/_/g
      INPUT: 'STDIN' line 1
      PATTERN: one
      COMMAND: H
      HOLD: none
      COMMAND: 1 h
      HOLD: one
      COMMAND: $ x
      COMMAND: $ s/n/_/g
      END-OF-CYCLE:
      one
      INPUT: 'STDIN' line 2
      PATTERN: two
      COMMAND: H
      HOLD: onentwo
      COMMAND: 1 h
      COMMAND: $ x
      PATTERN: onentwo
      HOLD: two
      COMMAND: $ s/n/_/g
      MATCHED REGEX REGISTERS
      regex[0] = 3-4 '
      '
      PATTERN: one_two
      END-OF-CYCLE:
      one_two


      I don’t know what distribution you use, but it’s not available yet in Debian, Ubuntu, or Fedora; it will be included in the next releases of Debian (10) and Ubuntu (19.04).






      share|improve this answer



























        5












        5








        5







        As fra-san mentioned, GNU sed introduced a --debug option which does pretty much what you’re looking for, in version 4.6; so e.g if you run:



        printf '%sn' one two | sed --debug 'H;1h;$x;$s/n/_/g'


        the output is



        SED PROGRAM:
        H
        1 h
        $ x
        $ s/n/_/g
        INPUT: 'STDIN' line 1
        PATTERN: one
        COMMAND: H
        HOLD: none
        COMMAND: 1 h
        HOLD: one
        COMMAND: $ x
        COMMAND: $ s/n/_/g
        END-OF-CYCLE:
        one
        INPUT: 'STDIN' line 2
        PATTERN: two
        COMMAND: H
        HOLD: onentwo
        COMMAND: 1 h
        COMMAND: $ x
        PATTERN: onentwo
        HOLD: two
        COMMAND: $ s/n/_/g
        MATCHED REGEX REGISTERS
        regex[0] = 3-4 '
        '
        PATTERN: one_two
        END-OF-CYCLE:
        one_two


        I don’t know what distribution you use, but it’s not available yet in Debian, Ubuntu, or Fedora; it will be included in the next releases of Debian (10) and Ubuntu (19.04).






        share|improve this answer















        As fra-san mentioned, GNU sed introduced a --debug option which does pretty much what you’re looking for, in version 4.6; so e.g if you run:



        printf '%sn' one two | sed --debug 'H;1h;$x;$s/n/_/g'


        the output is



        SED PROGRAM:
        H
        1 h
        $ x
        $ s/n/_/g
        INPUT: 'STDIN' line 1
        PATTERN: one
        COMMAND: H
        HOLD: none
        COMMAND: 1 h
        HOLD: one
        COMMAND: $ x
        COMMAND: $ s/n/_/g
        END-OF-CYCLE:
        one
        INPUT: 'STDIN' line 2
        PATTERN: two
        COMMAND: H
        HOLD: onentwo
        COMMAND: 1 h
        COMMAND: $ x
        PATTERN: onentwo
        HOLD: two
        COMMAND: $ s/n/_/g
        MATCHED REGEX REGISTERS
        regex[0] = 3-4 '
        '
        PATTERN: one_two
        END-OF-CYCLE:
        one_two


        I don’t know what distribution you use, but it’s not available yet in Debian, Ubuntu, or Fedora; it will be included in the next releases of Debian (10) and Ubuntu (19.04).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 6 at 22:18









        don_crissti

        50.3k15134162




        50.3k15134162










        answered Jan 6 at 22:09









        Stephen KittStephen Kitt

        167k24376454




        167k24376454



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492871%2fany-way-to-have-a-verbose-mode-or-debug-mode-with-sed%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

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

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay