Find the answer to your Linux question:
Results 1 to 2 of 2
Is it possible to mix and match regexp in sed? Code: sed 's#(\[0-9]\{1,2\}\)/
/
#11/17/79#' somefile I'm assuming that should evaluate to Code: sed 's#[0-9]\{1,2\}/[0-9]\{1,2\}/[0-9]\{1,2\}#11/17/79#' somfile...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    SED


    Is it possible to mix and match regexp in sed?
    Code:
    sed 's#(\[0-9]\{1,2\}\)/\1/\1#11/17/79#' somefile
    I'm assuming that should evaluate to
    Code:
    sed 's#[0-9]\{1,2\}/[0-9]\{1,2\}/[0-9]\{1,2\}#11/17/79#' somfile
    The best things in life are free.

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    No, it doesn't. Try reading regex(7). \1 is a backreference, which means that it doesn't match the same regexp as the parenthesized subexpression that it refers to, but it matches the same text that was previously matched by that parenthesized subexpressions.
    For example, while your second example matches 01/02/03, 11/58/97 and whatever, the first one only matches eg. 01/01/01, 52/52/52 and the likes. You get it?

Posting Permissions

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