Question: I am new to bash and having a tough time figuring this out.

Using `sed`, could anyone help me in finding only even numbers in a given file?

I figured out how to find all numbers starting from [0,2,4,6,8] using this:

```
sed -n 's/^[0-9]*[02468] /&/w even' <file 

```

But this doesn't guarantee that the number is even for sure.

I am having trouble in finding if the matched number ends with either [0,2,4,6,8] for it to be even for sure.

So can any one help me out with this?

Answer: 
Your regex looks a bit weird and I am not sure what you want to do, but this should help:

```
sed -r -n 's/^[0-9]*?[02468] /even/g'

```

`-r` to enable extended regex, `*?` to make it non-greedy, and `/g` to perform replacement globally for all lines in file.
```
$ cat file
1
2
3
498
57
12345678
$ awk '$0%2' file
1
3
57
$ awk '!($0%2)' file
2
498
12345678

```