Talk:sed

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia


Reference for claim?[edit]

Header added. —Nils von Barth (nbarth) (talk) 00:57, 13 October 2009 (UTC)[reply]

Is there a reference for the claim of the last sentence?

Sed's language does not have variables and only primitive GOTO and branching functionality; nevertheless, the language is Turing complete. --HJH

Lots of Google references to "sed turing complete" say so, and it is not unreasonable to think that it would be. Use the file as a tape, and a special reserved symbol inserted into the file to mark the head position, use replace expressions to implement the transformation rules, and GOTOs to change state.


Or just encode the state using a set of several different 'head' symbols.


While it isn't very feature rich, to say that sed has no variables I find a bit misleading. The following is an example of "variables" in sed:

$ echo -e "bear ape dog cat" | sed 's/\([a-z]*\)\ \([a-z]*\)\ \([a-z]*\)\ \([a-z]*\)/\2 \1 \4 \3/'

ape bear cat dog

and on a practical level, if you use double quotes rather than single quotes, shell variables can be used in sed. Just be mindful of "order of operations", bash syntax, for example, is very different from sed syntax. Even without the use of shell, such functions, while quickly complicated for things like calculations, this is enough to make it turing complete (consider the Turing Machine), if variables / registers are required. --199.80.142.27 (talk) 18:58, 21 May 2009 (UTC)[reply]

This may also be useful, a calculator written completely in sed: http://www.npcguild.org/~ksb/hack/math.sed --199.80.142.27 (talk) 19:03, 21 May 2009 (UTC)[reply]


Here's an example of a UTM in sed:

See this sed script (http://sed.sourceforge.net/grabbag/scripts/turing.sed) with the accompanying explanation (http://sed.sourceforge.net/grabbag/scripts/turing.txt) -- EricP 04:24, 30 November 2005 (UTC)[reply]

Cheat sheet[edit]

Header added. —Nils von Barth (nbarth) (talk) 00:57, 13 October 2009 (UTC)[reply]

I remove the "excellent" sed cheat sheet, which is constituted of copy pasted material from www.grymoire.com and the gnu manual. The author puts his copyright on this material, and fails to give credits ( and probably forgot to ask the permission from the author of the grymoire articles) even though he has been informed of this problems. —Preceding unsigned comment added by 146.124.141.250 (talk)


excellent cheat sheet is back, still no word of a permission to reproduce the content of www.grymoire.com, still no ack of copyright from the gnu sed man page. Users is spamming wikipedia with links to his websites —Preceding unsigned comment added by 146.124.141.250 (talk) 08:58, 15 November 2007 (UTC)[reply]

Primary page?[edit]

Header added. —Nils von Barth (nbarth) (talk) 00:57, 13 October 2009 (UTC)[reply]

Why is this the primary page for SED? Shouldn't the reader be redirected to the disambiguation page? Is this acronym that much more significant than the other posible uses of the initials? —Preceding unsigned comment added by 71.249.130.166 (talk) 08:51, 4 October 2007 (UTC)[reply]

The disambiguation page can be found at the top of this page. IMO this is by far the most common usage of the word. --Kompik 15:39, 4 October 2007 (UTC)[reply]

Sed not faster than Awk[edit]

Sed is not faster than AWK. Sed's "regular" expressions aren't regular (see Regular_expression, since it allows back-references. As a result, strings can not necessarily be matched in sub-exponential time.

Also, in my personal experience, gawk is faster than GNU sed for simple grep-like tasks.

Serviscope Minor 00:55, 4 December 2007 (UTC)[reply]

move history above usage, history source?[edit]

why history is in between usage and examples? i'm not sure how it can be done here, thus let this proposition here.

http://www.engin.umd.umich.edu/CIS/course.des/cis400/sed/sed.html

tells another, i.e. year 1977, timeframe about `sed` developement

Suggest page move[edit]

I think this page should be moved, possibly to SED (software), or another name, to allow the SED disambiguation page to take the SED name. There are other things referred to as SED that are much bigger than the UNIX software. For example, the flat panel display technology called SED (Surface-conduction electron-emitter display) is the main contender (along with OLED) to replace LCD and plasma displays. So SED will be up there with LCD and LED.--Lester 10:01, 4 December 2008 (UTC)[reply]

But SED already goes to the disambiguation page (and the software is called sed, not SED). --Zundark (talk) 10:11, 4 December 2008 (UTC)[reply]

Strange[edit]

Something strange happened that I do not understand: I've just added the link to Roger Chang's SED and Shell Scripts and while doing so thought that the 3. and and 4. could actually be removed since they are subpages of the first link, but I didn't do it. Then after saving the page with the one added link, I looked at the revision and saw that the second link had already been removed by IP 69.106.246.15 the last time the page was changed. Now it looks as if I had reinserted it although I did not. Please take a look at the revision: it cleary states that I added two links! I know, nobody will believe me, because the revision says so, but I swear I did not insert it! It was already there when I visited the page and led to me thinking about removing it. 62.226.32.173 (talk) 16:34, 18 February 2009 (UTC)[reply]

You are somehow reading the revision history incorrectly. It shows that you added only one link (the Roger Chang one), and made some inconsequential whitespace change to another link. It also shows that 69.106.246.15 removed a category, not a link.
I think a number of external links in this article (including the one you added) are inappropriate, and should be removed. --Zundark (talk) 16:54, 18 February 2009 (UTC)[reply]
Ah, ok then. But I do not understand why you want to remove the link I added. There isn't any better sorted sed script archive I know of, and it is a valuable resource for people using or learning sed. 62.226.31.103 (talk) 14:29, 25 February 2009 (UTC)[reply]

sed / tr example is wrong[edit]

The tr command provided in the Samples section does not do the same as the corresponding sed command. The tr command removes all line breaks, exchanging them with whitespace, while the sed command removes every line break that is succeeded by a whitespace on the next line (but doesn't add extra whitespace). 192.100.124.219 (talk) 11:08, 9 July 2009 (UTC)[reply]

sure, I remove the tr example. coco (talk) —Preceding undated comment added 08:19, 30 July 2009 (UTC).[reply]

Wikibook[edit]

I’ve created a Wikibook on sed (wikibooks:sed) – many edits to the ’Pedia sed page are non-encyclopedic, providing (admittedly useful) examples which are better suited to ’Books. Hope the new book meets with approval, and feel free to move content better suited to ’Books to the book!

—Nils von Barth (nbarth) (talk) 01:00, 13 October 2009 (UTC)[reply]

Link to exotic example 'tetris.sed' in russian?[edit]

The title has it all, I guess... Is it acceptable for a reference link to be in another language? This should probably go to the russian wikipedia page of "sed". Additionally, I could not see who made this change (how do I see who edited "that" part of an article?), but if someone uses "livejournal.com", please ask him at least make an intro in english. Thanks! —Preceding unsigned comment added by 85.72.161.183 (talk) 20:22, 29 November 2009 (UTC)[reply]

GNU regular expression library?[edit]

"minised was used by the GNU Project until the GNU Project wrote a new version of sed based on the new GNU regular expression library."

What's the GNU regular expression library? --Abdull (talk) 20:35, 16 February 2010 (UTC)[reply]

Can anyone verify "XML Table" example is correct?[edit]

Can anyone verify syntax in the "XML table into a CSV file" example is correct? Can anyone provide sample "XML table" input, and resulting "CSV file" output? If cannot be verified, maybe that complex example should be removed? 71.212.118.46 (talk) 05:53, 4 March 2013 (UTC)[reply]

Same question. 71.212.127.161 (talk) 02:06, 14 April 2013 (UTC)[reply]
I don't see any mistake in the syntax. The more serious problem is that it appears to be original research and makes various unstated assumptions about the input file format. For example, that it does not have a single root element and that the elements are nicely indented. I'd prefer to leave it out and put a link to sedtris in the external links section. 2001:558:6045:1D:56E:DCCB:ED9D:24EA (talk) 03:37, 4 May 2013 (UTC)[reply]
Thanks for striking the XML example. It seemed problematic as an example. I did move the sedtris example to what seems a better location in the article. 71.212.121.140 (talk) 22:03, 21 May 2013 (UTC)[reply]

SED and Exit Codes[edit]

The article does not discuss if SED sets an exit code (e.g., to indicate if the substitution happened or not) upon termination of program execution. I did find a statement in the GNU documentation (see the "External Links" section in the article), in the 'q' command description, of "The ability to return an exit code from the sed script is a GNU sed extension.", which implies other (most?) versions do not return an exit code? — Preceding unsigned comment added by Dan Aquinas (talkcontribs) 18:06, 12 June 2013 (UTC)[reply]

I am pretty sure all versions of sed return an exit code, but it has nothing to do with whether a substitution happened. The exit code is 0 if sed runs OK (does not crash), something else (usually 1) if sed crashes. For example, "sed s/xxx/yyy" has a syntax error (no trailing slash), so sed "bails out", returning 1. The exit code usage is the same as that for basically any Unix command, so it is not a big deal that the article does not discuss. As mentioned, GNU extensions allow you to specify your own exit code as part of the q or Q command. 71.212.122.128 (talk) 07:02, 15 July 2013 (UTC)[reply]

Concerns about theoretical text and language comparisons[edit]

I have some concerns about some of the recent edits in late August - early September.

First, I find the added theoretical discussion about how sed is "data-driven", and "imperative" unhelpful. I've used sed (and various programming languages) for decades. But I find the theoretical discussion confusing. So I pity the more general reader. sed is so different from mainstream programming languages such as C, perl, etc. So it's difficult to shoehorn sed into general categories. I have actually done "data-driven" programming. I disagree that it's helpful (or totally correct) to view sed as data-driven. As clearly stated in a comment, "Data-driven programming is a paradigm where the processing is controlled by values in data tables, rather than in program logic". The text processed by sed is NOT a data table. The sed script is more "program logic" than it is a "data table". Overall, to help the reader better understand sed, I think it's better to focus on what sed does, instead of potentially controversial / ambiguous theoretical discussions.

Second, I think it is best if we avoid saying "perl largely replaced sed" and other such comparative statements. These comparative statements have the potential to get into a "religious war". If the article becomes a "language comparison", there will be too much subjectivity and argument potential. sed, perl, awk, etc. are all useful. And they are rather different. I think it is a slippery slope discussing or implying which one is "better". 71.212.122.219 (talk) 21:49, 15 September 2013 (UTC)[reply]

Rationale for reverting very large edits[edit]

I reverted the large edits from July 11 and July 12. The edits increased the size of the article from 19,174 to 21,474 (a huge 12% increase), totally limited to the "Hello, world! example" section, and significantly damaged the article, as far as I could see. Given the obvious effort and good faith by the editor, I think it deserves to be explained why a reversion is called for.

First, other language articles only rarely have multiple "Hello, world!" examples. And if so, only for a really good reason. Most such sections are brief. There is no good reason for such a bloated "Hello, world!" section for sed.

The first added example (labeled "trivial") is not really a "Hello, world!" example, since the result depends on bash. The obscure bash "here string" syntax will certainly be confusing for most readers. This is an article about sed, not bash. The example actually says little or nothing about sed, since cat would work equally well. The edit says "evaluating a sed script on an empty file (such as produced by touch) blocks". That is an error. Try "touch brandnew; sed "" < brandnew". It does NOT block. The second point supposedly illustrated by the example ("Implicit default behavior is to match every line") is NOT illustrated by the example, so is just confusing verbiage. Finally, sed is NOT "data-driven", though the editor apparently disagrees. This has been discussed before. In any case, to help the reader better understand sed, I think it's better to focus on what sed does, instead of potentially controversial / ambiguous theoretical discussions about "data-driven".

The second added example (labeled "substantive") doesn't really add anything worth all the extra space. And the example is NOT quite similar to the AWK example, which uses BEGIN, which of course sed has nothing similar, so another confusing misstatement.

The final added example (labeled "sophisticated") just bogs the article down, since .* is totally redundant, as admitted by the editor. Hence the example is NOT "sophisticated", it's just the opposite, and a bad example. Finally, the remark about = command is out of context, since = is NOT used in the example. Talking about = in the middle of the example is disjointed and confusing.

Please do not take my remarks the wrong way. It helps having people look for improvements in the article, so please continue. But please do not try these kinds of massive edits. I'm sure you spent a lot of time. I had to spend a lot of time writing this. Given that you made so many errors, it's presumptuous of you to think you can overhaul this article. All the extra text did not improve the article, just bloated it up and made it more difficult to read. 71.35.174.206 (talk) 09:24, 25 July 2015 (UTC)[reply]

In popular culture...[edit]

IRC users might do


   <Blacksilver> Deblirvately msipelsled
   <Blacksilver> s/Deblirvately msipelsled/Deliberately misspelled/


To say "Oops, this is what I meant."

Additionally, Discord has a fascinating feature: you can type the same thing, and it will do the edit for you! There is no documentation for this as far as I can find. Perhaps we should add these (maybe not as in pop. culture)

174.138.203.63 (talk) 15:18, 18 June 2017 (UTC)[reply]

"any instance of a certain word" example[edit]

Should not the first example at "Other simple examples" include g in the sed instruction:

sed -i s/yourpassword/REDACTED/g ./status.freenode.log

...or else it would only substitute the first ocurrence of 'yourpassword' per line? -- Genoskill (talk) 20:40, 10 May 2021 (UTC)[reply]