Skip to main content
11 events
when toggle format what by license comment
Jan 22, 2018 at 3:44 vote accept Tinler
Jan 22, 2018 at 1:29 comment added cas @Tinler the difference between the two forms is that a & in the replacement inserts the entire match, while \1, \2, etc insert only a matched capture group. e.g. with s/the \(capture group\)/&/ vs s/the \(capture group\)/\1/. the & inserts "the capture group" into the replacement, \1 inserts only "capture group". There can be multiple capture groups in a search pattern, and they are referred to in numerical order - \1 is the first capture group, \2 is the second, etc.
Jan 22, 2018 at 1:12 comment added George Udosen This will also work: sed -E 's/([[:digit:]])/\1\1/'
Jan 22, 2018 at 1:02 comment added George Vasiliou OK. in gnu sed using \0 refers to the previously matched regex. In bsd sed this is done using &. So in your case since \0 does not work, you can use sed 's/[0-9]/&&/'. Actuall using & will work even in gnu sed.
Jan 22, 2018 at 0:51 comment added Tinler Yes. It becomes hew4r -> hew00r. I want hew44r. Also, why should I use that instead of "sed s/[0-9]/00/"? For this and the first example?
Jan 22, 2018 at 0:42 comment added Tinler "sed s/[0-9]/\0\0/" does the exact same as "sed s/[0-9]/00/" or am I missing something?
Jan 22, 2018 at 0:25 answer added John Smith timeline score: 2
Jan 22, 2018 at 0:20 history edited Tinler CC BY-SA 3.0
deleted 1 character in body
Jan 22, 2018 at 0:20 comment added Tinler My bad, I meant $sed s/[0-9]/00/ as you can see, it has to be zero. I'm looking for a way for the digit to be the one found in the [0-9].
Jan 22, 2018 at 0:13 comment added don_crissti How about reading the manual... You'll learn how to reference the matched portion, regardless of what's in the LHS. ;)
Jan 22, 2018 at 0:08 history asked Tinler CC BY-SA 3.0