Results 1 to 4 of 4

Thread: sed

  1. #1
    Join Date
    May 2004
    Posts
    11

    Unanswered: sed

    Hi

    does anyone know what does the sed command do:

    sed "s/[A-Z]/&/g" file

    i tried running but there is no effect on the uppercase letters in the file. Is the amperstand a metacharacter in sed?

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    This isn't going to do anything that you would notice!

    '&' in a substitution represents the pattern that was matched, so you are replacing your character A-Z, with that same character.

    Try...

    sed "s/[A-Z]/&&/g" file

    ...and you will see each character repeated because you are replacing the matched pattern with 'twice' the matched pattern.

  3. #3
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Quote Originally Posted by Daryl Lim
    Hi

    does anyone know what does the sed command do:

    sed "s/[A-Z]/&/g" file

    i tried running but there is no effect on the uppercase letters in the file. Is the amperstand a metacharacter in sed?
    this sed does not change anything.
    '&' back-references the matched string.

    doing 'man sed' yields:
    An ampersand (&) appearing in the replacement
    will be replaced by the string matching the
    RE. The special meaning of & in this context
    can be suppressed by preceding it by
    backslash. The characters \n, where n is a
    digit, will be replaced by the text matched by
    the corresponding backreference expression.
    For each backslash (\) encountered in scanning
    replacement from beginning to end, the follow-
    ing character loses its special meaning (if
    any). It is unspecified what special meaning
    is given to any character other than &, \ or
    digits.

  4. #4
    Join Date
    May 2004
    Posts
    11

    sed

    what about this command below:

    sed "10r text" file

    thanks
    daryl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •