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.

  • Is l;x;l;x; at the start & end of the program adequate? – Michael Homer Jan 6 at 19:36
  • 2
    It looks like GNU sed gained a --debug feature last summer (version 4.6). – fra-san Jan 6 at 19:56
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 '%s\n' 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:    one\ntwo
COMMAND: 1 h
COMMAND: $ x
PATTERN: one\ntwo
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.