Question: I have the following file (F1):

```
if a equals b
you
three aggbc four

```

I want the output to be:

```
if a equals b b b
you you you
three aggbc four four four

```

I run the following command:

```
sed -re 's/.*([^ ]+)[ |$]/\0 \1 \1/' F1

```

But it wont work.

The output I get is wrong:

```
if a equals  s sb
you
three aggbc  c cfour

```

I need it as a `sed` command.

Answer: 
```
sed -r 's/^(.* )?(.*)$/\1\2 \2 \2/' F1

```
Regex specials lose their special meaning inside a character class. So `[ |$]` matches a single character which can be space, pipe, or dollar sign. Try this instead;

```
sed -re 's/.*([^ ]+) *$/& \1 \1/' F1

```

Also notice that I changed `\0` to `&`. I haven't seen `\0` in `sed` but if yours supports it, more power to you.