FreeKB - Bash (Scripting) Add a leading zero to single digit numbers in Linux
Bash (Scripting) - Add a leading zero to single digit numbers in Linux

Let's say file1.txt contains both single digit and multiple digit numbers.

8
15
4
13
5
4
12

 

The following sed statement will add a leading 0 to the single digit numbers.

~]# cat file1.txt | sed -i 's/\<[0-9]\>/0&/'

 

The sed statement will update file1.txt.

08
15
04
13
05
04
12

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 7eeea in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |