bug-sed
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#56764: Sed man page omits 'g' flag for substitute command


From: Tom Ekberg
Subject: bug#56764: Sed man page omits 'g' flag for substitute command
Date: Mon, 25 Jul 2022 17:02:55 +0000

The sed man page has a synopsis for the substitute command (s) which is:

s/regexp/replacement/

I have to go to the sed FAQ 
(http://sed.sourceforge.net/grabbag/tutorials/sedfaq.txt), section 3.1.3, 
Substitution switches, to get a list of the possible switches. While there are 
8 switches I use 'g' most often to do a global search/replace on the input 
line. Without this, only the first match is replaced. The FAQ also describes 
the 'I' switch for doing a case-insensitive search which may be useful in 
certain cases. The other 6 switches I have never used: N (a number), p, w, M, 
S, and X.

The version and date on the Ubuntu 20.04 sed man page is sed 4.7, December 
2018. The AIX V7.1 man page for sed does contain a description of the 's' 
switches (flags). Here is what that man page says about the 's' command:

s/pattern/replacement/flags
    Substitutes the replacement string for the first occurrence of the
    pattern parameter in the pattern space. Any character that is
    displayed after the s subcommand can substitute for the / (slash)
    separator except for the space or new-line character.

    See the Pattern Matching section of the ed command.

    The value of the flags variable must be zero or more of:
      g
        Substitutes all non-overlapping instances of the pattern
        parameter rather than just the first one.
      n
        Substitutes for the n-th occurrence only of the pattern
        parameter.
      p
        Writes the pattern space to standard output if a
        replacement was made.
      w WFile
        Writes the pattern space to the WFile variable if a
        replacement was made. Appends the pattern space to the
        WFile variable. If the WFile variable was not already
        created by a previous write by this sed script, the sed
        command creates it.

I was unable to find a version number on the AIX sed man page or the executable 
(cat /usr/bin/sed |strings -3|sort|uniq|less). That man page doesn't list a 
-version or -V command line option. They don't work anyway.

The sed man page should, when describing the 's' command, at least describe the 
'g' switch, and maybe also describe the 'I' switch.

Tom Ekberg
Senior Computer Specialist
Department of Laboratory Medicine and Pathology
4th Floor, Pat Steel Building, currently WFH
Home: (253) 561-2509
Email: tekberg@uw.edu<mailto:tekberg@uw.edu>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]