- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Adding leading zeroes to text in a file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2011 11:05 AM
07-12-2011 11:05 AM
Hello all,
I'm creating a tag file and need to fill in a 4 digit field with a number and leading zeros. For example, I would need to turn this:
74
5
143
into this:
0074
0005
0143
Is this possible? Thanks,
-Eric
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2011 11:26 AM
07-12-2011 11:26 AM
Solution> I'm creating a tag file [...]
Tells me approximately nothing. I'll assume a shell script to
process an existing file.
Not very efficient, but...
$ cat nlz.txt
74
5
143
$ ( while read line ; do echo "0000$line" | sed -e 's/.*\(....\)/\1/' ; done ) < nlz.txt
0074
0005
0143
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2011 11:40 AM
07-12-2011 11:40 AM
Re: Adding leading zeroes to text in a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2011 11:50 AM
07-12-2011 11:50 AM
Re: Adding leading zeroes to text in a file
Hi:
Another way:
# while read line;do printf "%04d\n" $line;done < file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2011 04:48 PM
07-12-2011 04:48 PM
Re: Adding leading zeroes to text in a file
If you want leading zeros in your shell variables, you can use:
typeset -Z4 variable=0
echo $variable
0000
In your case you can read your file and assign to "variable" and then print it out.
for variable in $(< file); do
echo $variable
done