Sed Command Validator

Paste a sed command to check its syntax and read what each part does in plain English. Unterminated substitutions, unknown commands, bad flags, and unbalanced braces are caught before you run it.

Updated
Runs in your browser. Your data is not uploaded.
What it does
    Checks as you type.

    How to use the Sed Command Validator

    1. Open the Validate tab and paste a full command such as sed -n '/start/,/end/p' log.txt, or only the script.
    2. The command is checked as you type. Press Validate to check it again.
    3. Read the list of problems, if any, then the step-by-step explanation of the options and each command.

    How it works

    • The command line is split the way a POSIX shell would split it, respecting single and double quotes. An unclosed quote is reported first.
    • Options are recognised: -n, -e, -f, -i with or without a suffix, -E and -r, -s, and -z.
    • The script is split into commands at ; and line breaks. Each command's address is parsed: line numbers, $, /regex/, ranges, first~step, and ! negation.
    • Commands s and y must have all three delimiters. The flags of s must be from g, p, i/I, m/M, e, w file, or a number, and y needs source and target of equal length.
    • Each { needs a matching }. Patterns are test-compiled to catch unbalanced brackets and groups.

    Examples

    • sed 's/foo/bar' file: error, the s command is missing its closing delimiter. Write s/foo/bar/.
    • sed 's/a/b/x' file: error, x is not a valid flag for s.
    • sed '/start/,/end/{s/old/new/g' file: error, the { is never closed.
    • sed -i 's/\bcat\b/dog/g' notes.txt: valid on GNU sed, with a warning that \b and -i without a suffix don't work on macOS.
    • sed -n '/^#/!p' config: valid. Explanation: don't print lines automatically; for every line that does not start with #, print it.

    Limitations

    • The validator checks syntax, not what the command will do to your data. Test on a copy of the file before using -i.
    • Scripts loaded with -f script.sed can't be read. Paste the script's contents instead.
    • Shell variables such as $HOME inside double quotes are not expanded.
    • Regex checking uses JavaScript's engine, so a few POSIX-only constructs may be reported as warnings.

    Frequently asked questions

    Why does my sed command say 'unterminated s command'?

    The s command needs three delimiters: s/find/replace/. It usually means the final slash is missing, or the text contains an unescaped /. Use another delimiter such as s|a/b|c|.

    What is the difference between GNU sed and BSD sed?

    Linux uses GNU sed. macOS and FreeBSD use BSD sed, which needs a suffix after -i, has no I flag, and doesn't support \b, \+, or one-line a text. The validator marks GNU-only features.

    Can I paste just the script without sed and the file?

    Yes. If the input doesn't start with sed, it is treated as the script itself.

    Is my command uploaded?

    No. It is checked in your browser.

    Often used together with the Sed Command Validator.

    • Sed Command Generator

      Builds sed commands for substitution, deletion, printing, and inserts, with a live preview.

    • Regex Tester

      Highlights regex matches live, lists capture groups and offsets, and previews replacements.

    • .htaccess Validator

      Checks .htaccess files for unknown directives, unclosed blocks, and bad rewrite rules.