As we all know, sed can read commands from one or more script files (or from stdin1) via -f.
This comes in handy when we need to make changes based on a list of patterns (or line numbers) as we can process the lines and turn them into editing commands which we then pass to sed. Sometimes the list is huge though so my question is

Is there a limit to the number of lines/editing commands that can be used in a sed script2 ?

1: not all implementations support that though...
2: where script is obtained from combining all the -e script and -f script_file options

  • My own testing using a sed -f file with 500,000 lines works fine. Of what magnitude are you testing against ? – steve Nov 10 '16 at 20:55
  • As far as I read on manuals, there is no limitations about the number of lines/editing commands in a sed script. Does it seem so to you? – andreatsh Nov 10 '16 at 22:19
  • Are we looking for limits in various implementations? – Jeff Schaller Nov 10 '16 at 22:41
  • Just curious what kind of answers you're looking for ("sed 1.2 on whonix 4.5 goes up to 2 million") – Jeff Schaller Nov 10 '16 at 22:49
  • 2
    @JeffSchaller - something like that or no, there's no limit - except your RAM – don_crissti Nov 10 '16 at 22:50

A brief glance at the source code of GNU sed 4.2.2 reveals a lot of malloc calls, and no boiled-in size constants. So, no, there's no limit - except your RAM.

|improve this answer|||||

sed on OpenBSD 6.1: RAM is the limit.

The specific things that could cause trouble (if you are persistent about it) are:

  1. Excessive number of labels (in the order of an int, I believe).
  2. Filling up the hold space with too much data (in the magnitude of size_t).
  3. Too long input lines (input data or script, but handles lines up to size_t length).

The sed script itself is compiled into a linked list structure.

|improve this answer|||||

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.