Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add "0" 1

Status
Not open for further replies.

Castelior

Programmer
Apr 13, 2004
3
FR
Hi guys.

I have a file :

1
2
10
123

and I want :

0001
0002
0010
0123

My script is a shell.
I don't know if i should used "sed" or "awk" or "printf"

Thinks!
 
Either:
Code:
#!/usr/bin/ksh
typeset -Z4 result
cat test.txt | while read result
do
    echo $result
done
Or:
Code:
#!/usr/bin/ksh
cat test.txt | while read result
do
    printf "%04d\n" $result
done
Plus many other ways using awk, perl, etc... :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top