Question: The output of `du -sh folder` is some dimension and folder; how can I use `grep -o '*G'` and similar to just get the dimension, namely get rid of folder name?

Answer: 
I can offer a simple `cut` solution :

```
du -sh . | cut -f1

```

The standard delimiter in `cut` is tab, so no need for any additional options. Simply print field 1.

From your comment, it seems you are concerned with resources/speed so to quote Gilles from another answer:

> 
> "Generally speaking, the more specialized a tool is, the faster it is.
>  So in most cases, you can expect `cut` and `grep` to be faster than `sed`,
>  and `sed` to be faster than `awk`." 
> 
> 
> 

Quoted from [here](https://unix.stackexchange.com/questions/132313/what-are-the-exact-differences-between-awk-and-cut-with-grep)

The ouput of `time` for both commands shows:

```
time du -sh /folder | awk '{print $1}'
60K

real    0m0.005s
user    0m0.002s
sys     0m0.004s

time du -sh /folder | cut -f1
60k

real    0m0.003s
user    0m0.000s
sys     0m0.004s

```

I believe you would need to repeat that multiple times, and take the average to make it a fair test, but either way, not much in it. Technically cut should be "faster".
You could use awk to only print the first column:

```
du -sh folder | awk '{print $1}'

```

For the file, also using awk:

```
awk '!($3="")' file

```