- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Leading Zeros
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
Forums
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
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
01-09-2003 05:07 PM
01-09-2003 05:07 PM
For the purpose of this discussion I am pulling a 6-character record count from file_1 and inserting the result into file_2 using the cut command. The record count has leading zeros. Is there an easy way to either get rid of the leading zeros, or use the cut or another command on file_2 to grab everything beyond the leading zeros? The result would end up in file_3. I tried translate (tr) but that got rid of all the zeros.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2003 05:23 PM
01-09-2003 05:23 PM
Re: Leading Zeros
One more best thing would be to use sed command and replace all leading zeros with null.
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2003 08:22 PM
01-09-2003 08:22 PM
Re: Leading Zeros
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2003 09:13 PM
01-09-2003 09:13 PM
Re: Leading Zeros
Both have advantages and disadvantages.
It depends on the type of records that you pull out. typeset can really change the output if it is not used carefully. (for ex typeset a variable as integer and see what will happen if the input has characters). And sometimes it will leave no choice except to use awk or sed.
echo $WORD|sed 's/^0*//' will not change the type of your input records. But on the other hand, if you don't do substitution correctly, you will get the wrong results.
Make the choice based on the type of data that is passed.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2003 09:41 PM
01-09-2003 09:41 PM
Re: Leading Zeros
In your SHELL Script you can enter...
1. grep 0*
2. check the value of $?.
if $?=0, then you have a leading 0 in your
give it a try...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2003 10:40 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2003 11:11 PM
01-09-2003 11:11 PM
Re: Leading Zeros
x="000012"
y=${x##*0}
# y will be 12
if [ "$x" = "$y" ] ; then
echo "No leading zero"
else
echo "Yes leading zero"
fi
# will display "yes leading zero"
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2003 08:38 AM
01-10-2003 08:38 AM
Re: Leading Zeros
while [ "$run" = "1" ]
do
z=$(cat file_1 | awk '{print $1}' | grep ^0)
if [ "$z" != "" ]
then
cat file_1 | sed 's/^0//g' > file_tmp
mv file_tmp file_1
elif [ "$z" = "" ]
then
run=0
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2003 11:43 AM
01-10-2003 11:43 AM