I have file like this:
pup@pup:~/perl_test$ cat numbers
1234567891
2133123131
4324234243
4356257472
3465645768000
3424242423
3543676586
3564578765
6585645646000
0001212122
1212121122
0003232322
In the above file I want to remove the leading and trailing zeroes so the output will be like this
pup@pup:~/perl_test$ cat numbers
1234567891
2133123131
4324234243
4356257472
3465645768
3424242423
3543676586
3564578765
6585645646
1212122
1212121122
3232322
How to achieve this? I tried sed
to remove those zeroes. It was easy to remove the trailing zeroes but not the leading zeroes.
Help me.
[0]*
instead of0+
? First, there is no need to use[...]
, and more importantly you want one or more instances, so use+
and not*
. Furthermore, you may combine both patterns into one:sed -r 's/^0+|0+$//g' numbers
– Toots