Monday, December 1, 2008

Replace leading zero 0 with blanks using sed


Input file:

$ cat thres.txt
0002345
01234
0901234
0000034
14
000923

Required: Remove the leading zero's with blanks from the above file.

The sed solution:


$ sed -e 's/^0/ /;: loop' -e 's/ 0/ /;t loop' thres.txt


Output:


2345
1234
901234
34
14
923

1 comment:

Navneet Jadhav said...

Hi,

I invite you and your readers to contentxn.com.

Registering for an exclusive contentxn publisher account only takes a minute of your time to register click the link below
http://www.contentxn.com/contentxn/pub_register.php

We look forward to working with you.
Cheers,
www.contentxn.com

© Jadu Saikia www.UNIXCL.com