summaryrefslogtreecommitdiff
path: root/usr.bin/sed
AgeCommit message (Collapse)Author
2024-08-28Fix the case where the pattern space is empty but does not startTodd C. Miller
with a NUL character, which might occur after using the D command. From Mohamed Akram
2024-07-17sed: use warn()/err() where appropriateTodd C. Miller
Use warn()/err() instead of sed's homegrown warning()/error() for things other than parser problems. The warning()/error() functions display the file and line number in addition to the error message. This also removes of the COMPILE/FATAL argument to error() since now all calls to error() are for compilation/parsing issues. OK op@ espie@
2024-07-17Display an error message for "sed -i" if the file is unwritableTodd C. Miller
Previously, sed would fail silently if it was unable to move the temporary file into place. Also allow "sed -i" on symbolic link--the link will be broken but this matches GNU sed behavior. From espie@ OK op@
2024-06-18Rename mf_fgets() and cu_fgets() to mf_getline() and cu_getline().Todd C. Miller
These functions now use getline(), not fgets(). From espie@
2023-02-08sed: add missing void to avoid -Wstrict-prototype with clang 15Theo Buehler
2022-12-28the S in CSRC is Science not SciencesJonathan Gray
2022-12-26spelling fixes; from paul tagliamonteJason McIntyre
amendments to his diff are noted on tech
2022-12-04userspace: remove vestigial '?' cases from top-level getopt(3) loopsScott Soule Cheloha
getopt(3) returns '?' when it encounters a flag not present in the in the optstring or if a flag is missing its option argument. We can handle this case with the "default" failure case with no loss of legibility. Hence, remove all the redundant "case '?':" lines. Prompted by dlg@. With help from dlg@ and millert@. Link: https://marc.info/?l=openbsd-tech&m=167011979726449&w=2 ok naddy@ millert@ dlg@
2022-09-14clarify behaviour when the second address in a range is smaller thanJason McIntyre
or equal to the first; diff from luka krmpotic ok kn
2022-08-03sed(1) first appeared outside of Bell Labs in PWB/UNIX 1.0Jonathan Gray
it did not start in the PWB group "The talk said that tools like grep and sed came from PWB, but that's not true. They were original" "The flow from PWB back to the main research line was a trickle at best. We had bad NIH in 1127." Rob Pike https://minnie.tuhs.org/pipermail/tuhs/2020-February/020329.html The 4.4BSD version was written by Diomidis Spinellis credited in csrg/admin/admin/contrib "In 1992, as a bored PhD student, I reimplemented sed(1) and contributed it the unencumbered BSD version that was then being put together" https://www.spinellis.gr/blog/FreeBSD.html with and ok schwarze@
2022-01-12Make lputs use psl instead of expecting it to be null-terminated.Martijn van Duren
This allows us to enable the commandl1 and commandl2 regress tests. Original analysis from seL4 <at> disroot <dot> org OK millert@
2021-03-08Add some references, most of these were removed when we stopped buildingJonathan Gray
and installing USD/SMM/PSD docs. jmc@ agrees with the direction, ok millert@ on an earlier diff
2021-01-31replace fgetln(3) with getline(3) in sedChristian Weisgerber
Partly from Johann Oskarsson for Illumos/FreeBSD. ok millert@
2020-10-16double word fixes; from varik valeforJason McIntyre
2020-10-13Un-const what we pass to dirname(3).Martijn van Duren
Original diff by and OK naddy@
2018-12-10correct inaccurate and misplaced information in CAVEATSIngo Schwarze
and move it in part to the DESCRIPTION, in part to STANDARDS; triggered by a loosely related bug report from Lars dot Nooden at gmail dot com; OK jmc@, and no opposition when shown on bugs@
2018-12-08revert previous, it breaks regress and the llvm, gtk+2, and gtk+3 portsIngo Schwarze
because it changes the behaviour for empty input files; revert requested by naddy@ and sthen@
2018-12-07As an extension to POSIX, for consistency with our behaviour forIngo Schwarze
the "b" and "t" commands with a label, and for compatibility with GNU sed, also accept ";" followed by another command after "b" and "t" commands without a label: branch to the end of the script instead of erroring out. Parsing is unchanged. Missing feature reported by Lars dot Nooden at gmail dot com on bugs@. OK martijn@ millert@
2018-12-06Add support for "-" as an input file for stdin as per POSIX.Martijn van Duren
Simplify the code by allowing usage of stdin with the -i flag by pushing the result to stdout, so filters and in place editing can be combined. OK millert@
2018-11-14Make sed's -i flag more compatible with what gsed does.Martijn van Duren
- Reset the hold-space in between files - quit the editor as soon as a 'q' command is found - Make sure the temp-file is written back to the original file if we quit the editor temp-file not written back issue found by Time Chase. Lots of feedback from millert@ and schwarze@ OK millert@
2018-08-14Improve consistency of the substitution command further.Ingo Schwarze
When the opening square bracket ('[') is abused as the delimiter, the regular expression contains a bracket expression, and the bracket expression contains another opening square bracket (sick! - i mean, sic!), then do not require escaping that innermost bracket and treat a preceding backslash as a literal backslash character, in accordance with POSIX: $ printf 'x[x\\x\n' | sed 's[\[[][R[g' xRx\x $ printf 'x[x\\x\n' | sed 's[\[\[][R[g' xRxRx While here, also make the implementation more readable and insert some comments. Joint work with martijn@ (started during g2k18) and OK martijn@.
2018-07-11Make the output of the list command more sensible for the output device.Martijn van Duren
We now output $COLUMNS - 8 characters of the string and a newline. This is similar to the behaviour in ed(1). Discussed with and OK schwarze@
2018-07-11Rephrase the wording on the replacement string of the substitute command.Martijn van Duren
Cover more cases with less wording. Joint work with schwarze@ OK millert@
2018-07-10Disentangle the "SED ADDRESSES", "SED REGULAR EXPRESSIONS",Ingo Schwarze
and "s/// command" sections and clarify what an escaped delimiter does inside regular expressions and inside character classes. Joint work with martijn@, no objection from jmc@.
2018-07-09When using '[' as the delimiter in sed(1) s/// (don't do that, of course)Ingo Schwarze
and then including '[' in the regular expression by prepending a backslash to it, remove the backslash before feeding the RE to the RE engine, just like we already do it for other special characters like .^$*+?{(|. This makes sed 's[\[xy][...[' treat the xy thingy as a char class. Joint work with martijn@, OK guenther@ martijn@
2017-12-19Remove EXAMPLES section.Martijn van Duren
The example itself was taken directly from the POSIX specification by jmc@, who doesn't remember adding it. This example isn't very clear about what it actually does, so just remove it. If someone can come up with one or more examples that give a more clear introduction to the workings of sed feel free to send them in. Prompted by a diff by kshe59 <at> zoho <dot> eu OK jmc@
2017-12-13Fix array index by signed char; from martijn@Todd C. Miller
2017-12-13Fix sign compare warnings; OK martijn@Todd C. Miller
2017-12-13Enable compiler warnings; OK martijn@Todd C. Miller
2017-12-12Fix 2 bugs introduced by previous.Martijn van Duren
Pointed out by kshe59 <at> zoho <dot> eu OK millert@
2017-12-11Fix and change y command in the following ways:Martijn van Duren
- When 'n' is used as a delimiter escaping 'n' will remain a newline instead of becoming a 'n' character. This is how POSIX specifies how this should work. Other implementations tested also do this wrong. - '[' and maybe other characters are not special during the parsing of the y command and don't need to be matched or treated special in any way. - POSIX specifies that a backslash followed by anything other than the delimiter, 'n', and another backslash, as well as repeating characters in string1 are unspecified. Since the various implementations handle these situations in opposing ways choose to error out on them to prevent people falling into the pitfall of expecting identical behaviour on various implementations. Inspired by the sed.1 patch by kshe59 <at> zoho <dot> eu Feedback and OK millert@ Manpage bits OK jmc@
2017-12-08Make the r command filename obligatory, similar to what FreeBSD and NetBSDMartijn van Duren
do for several years. While here make corresponding error message for missing read and write file consistent between commands/flag, and shrink the the code of the w flag of the s command by making it use the same code as the w command. Prompted by a larger diff by kshe59 <at> zoho <dot> eu OK millert@
2017-12-07Make the command formatting more consistent.Martijn van Duren
s/with/width type-O fix while here. From kshe59 <at> zoho <dot> eu OK jmc@
2017-08-01Apply stricter pledge rules if possible. These are based on the usage ofMartijn van Duren
the 'w' and 'r' functions and the 'w' flag to the 's' function. If non of the above is used and input is being read from stdin, we drop all the way down to stdio! Original inspiration by benno@. OK millert@
2017-07-19remove some spacing; ok schwarzeJason McIntyre
2017-02-22Remove unused-with-dead-store variable oldpsanl.Tom Cosgrove
From Daniel Cegielka - thanks ok jca@
2017-01-21Nuke more whitespace caught in the headlights of "warning:"Kenneth R Westerback
rectification.
2017-01-20Split error() into error() and warning() so error() can be marked __dead toKenneth R Westerback
appease gcc. ok procter@ deraadt@
2016-10-26make it clear that the s/// numeric flag can containIngo Schwarze
more than one digit but cannot start with zero; feedback and OK jmc@, OK jca@, OK millert@ on an earlier version
2016-10-11Fix an off by one error when no matches were found in a substitute.Martijn van Duren
By pfg@ from FreeBSD OK millert@ and otto@
2016-07-14make several program to use "chown" promise.Sebastien Marie
it allows chown(2) call to change the user or group on a file. - usr.bin/compress : aka gzip - usr.bin/mg : open a file for writing - usr.bin/sed : inplace editing - usr.bin/sort : if outfile equals one of the input files ok deraadt@ tb@ (and a reminder from Remi Locherer) warning: in order to use it, you must have a recent kernel with the new promise.
2016-05-30Make sed use the new REG_STARTEND | REG_NOTBOL combination. This fixes a beginMartijn van Duren
of word mismatch as reported by jsg@. Discussed with otto@ and others early on, earlier version tested in ports build by aja@ OK millert@ Few readability tweaks and OK schwarze@
2016-03-17Switch (non-curses, non-ksh) programs that use COLUMNS to a single idiom.Anthony J. Bentley
Previously behaviors were all over the map. This changes them to use COLUMNS first, and either terminal width or a hardcoded value (typically 80) as appropriate. ok deraadt@; man bits ok jmc@
2016-01-01Improve error message for sed -i by appending strerror(errno).tb
From Michael Reed, thanks! ok deraadt@
2015-11-04replace setbuf with setvbuf, from Frederic NowakTed Unangst
2015-10-26Tidy up error() levels: merge COMPILE and COMPILE2, and kill ERROR (unused)Jeremie Courreges-Anglas
ok tobias@
2015-10-26Use error(FATAL) instead of what was previously err(1,...)Jeremie Courreges-Anglas
ok tobias@
2015-10-26Rename err() to error() to prevent confusion with the stdlib function.mmcc
Discussed with jca@.
2015-10-25Write error message instead of duplicated file name on error.Tobias Stoeckmann
ok deraadt
2015-10-10normalize the ordering of tame requests (particularily, "rpath wpath cpath",Theo de Raadt
which i have put in that order). this is not important, but helps look for outliers which might be strange. it hints that "ioctl" should be reassessed in a few places, to see if "tty" is better; that "unix" may be used in some places where "route" could now work.