Bash increment alphanumeric data from command prompt
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I need to increment alphanumeric data.
Increment numbers with seq
is easy just: seq -w 0000001 9999999 >> file
But I need to increment alphanumeric data in order like this:
0000001
0000002
0000003
0000004
0000005
0000006
0000007
0000008
0000009
000000a
000000b
000000c
000000d
000000e
0000010
0000011
0000012
0000013
0000014
0000015
0000016
0000017
0000018
0000019
000001a
000001b
000001c
000001d
000001e
0000020
0000021
etc... until I hit eeeeeee
Using alphanumeric data 0-9a-e
. Just need to load the data in an empty file and done. Is there an easy bash command for this something similar to the seq
command? I'm using Linux Debian 6.3.0-18 and Bourne Again Shell.
bash shell-script command-line
add a comment |Â
up vote
0
down vote
favorite
I need to increment alphanumeric data.
Increment numbers with seq
is easy just: seq -w 0000001 9999999 >> file
But I need to increment alphanumeric data in order like this:
0000001
0000002
0000003
0000004
0000005
0000006
0000007
0000008
0000009
000000a
000000b
000000c
000000d
000000e
0000010
0000011
0000012
0000013
0000014
0000015
0000016
0000017
0000018
0000019
000001a
000001b
000001c
000001d
000001e
0000020
0000021
etc... until I hit eeeeeee
Using alphanumeric data 0-9a-e
. Just need to load the data in an empty file and done. Is there an easy bash command for this something similar to the seq
command? I'm using Linux Debian 6.3.0-18 and Bourne Again Shell.
bash shell-script command-line
These are numeric data in hex. They are not arbitrary alphanumeric data.
â NickD
Mar 24 at 3:44
2
I don't see any f in there: are you sure that it should not be there? That would be base 15 numeric data which seems ... strange.
â NickD
Mar 24 at 3:57
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to increment alphanumeric data.
Increment numbers with seq
is easy just: seq -w 0000001 9999999 >> file
But I need to increment alphanumeric data in order like this:
0000001
0000002
0000003
0000004
0000005
0000006
0000007
0000008
0000009
000000a
000000b
000000c
000000d
000000e
0000010
0000011
0000012
0000013
0000014
0000015
0000016
0000017
0000018
0000019
000001a
000001b
000001c
000001d
000001e
0000020
0000021
etc... until I hit eeeeeee
Using alphanumeric data 0-9a-e
. Just need to load the data in an empty file and done. Is there an easy bash command for this something similar to the seq
command? I'm using Linux Debian 6.3.0-18 and Bourne Again Shell.
bash shell-script command-line
I need to increment alphanumeric data.
Increment numbers with seq
is easy just: seq -w 0000001 9999999 >> file
But I need to increment alphanumeric data in order like this:
0000001
0000002
0000003
0000004
0000005
0000006
0000007
0000008
0000009
000000a
000000b
000000c
000000d
000000e
0000010
0000011
0000012
0000013
0000014
0000015
0000016
0000017
0000018
0000019
000001a
000001b
000001c
000001d
000001e
0000020
0000021
etc... until I hit eeeeeee
Using alphanumeric data 0-9a-e
. Just need to load the data in an empty file and done. Is there an easy bash command for this something similar to the seq
command? I'm using Linux Debian 6.3.0-18 and Bourne Again Shell.
bash shell-script command-line
edited Mar 24 at 3:55
Kevin
25.7k95797
25.7k95797
asked Mar 24 at 3:03
RainyDay
103
103
These are numeric data in hex. They are not arbitrary alphanumeric data.
â NickD
Mar 24 at 3:44
2
I don't see any f in there: are you sure that it should not be there? That would be base 15 numeric data which seems ... strange.
â NickD
Mar 24 at 3:57
add a comment |Â
These are numeric data in hex. They are not arbitrary alphanumeric data.
â NickD
Mar 24 at 3:44
2
I don't see any f in there: are you sure that it should not be there? That would be base 15 numeric data which seems ... strange.
â NickD
Mar 24 at 3:57
These are numeric data in hex. They are not arbitrary alphanumeric data.
â NickD
Mar 24 at 3:44
These are numeric data in hex. They are not arbitrary alphanumeric data.
â NickD
Mar 24 at 3:44
2
2
I don't see any f in there: are you sure that it should not be there? That would be base 15 numeric data which seems ... strange.
â NickD
Mar 24 at 3:57
I don't see any f in there: are you sure that it should not be there? That would be base 15 numeric data which seems ... strange.
â NickD
Mar 24 at 3:57
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Assuming you really mean hex (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) here is a solution up to FF (I don't want to have to count to 4.3 billion):
(echo obase=16; seq 1 $((echo ibase=16; echo FF) | bc)) | bc
The inner
(echo ibase=16; echo FF) | bc
calculates the ending value in decimal (here FF but feel free to substitute FFFFFFFF if you want :-). The seq
then counts from one to 255 in this case, and the rest converts it to hex.
And if you really want base 15, you can change both 16's to 15's (and the FF... to EE...).
This is exactly what I was looking for. How can I make it start at 0000001 instead of 1?
â RainyDay
Mar 24 at 6:57
You could pipe that command into| xargs printf "%7sn" | tr ' ' 0
â glenn jackman
Mar 24 at 11:10
add a comment |Â
up vote
1
down vote
Just play with the print operators
#!/bin/bash
for number in $( seq 1 255 )
do
hex_representation=$( printf "%X" $number )
echo "$number: $hex_representation"
done
2
Or justprintf '%06Xn' $(seq 1 255)
(I added zero padding in line with the OP's desired output format)
â steeldriver
Mar 24 at 11:49
This answer is also a good solution. In the loop how can I control the output? In the loop 0000001 is sent to an empty file like this: printf '%06Xn' $(seq 1 255) > file. Then on second loop cycle 0000002 is sent into the file, etc. Is there a simple way to pause this command until next loop?
â RainyDay
Mar 26 at 3:37
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Assuming you really mean hex (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) here is a solution up to FF (I don't want to have to count to 4.3 billion):
(echo obase=16; seq 1 $((echo ibase=16; echo FF) | bc)) | bc
The inner
(echo ibase=16; echo FF) | bc
calculates the ending value in decimal (here FF but feel free to substitute FFFFFFFF if you want :-). The seq
then counts from one to 255 in this case, and the rest converts it to hex.
And if you really want base 15, you can change both 16's to 15's (and the FF... to EE...).
This is exactly what I was looking for. How can I make it start at 0000001 instead of 1?
â RainyDay
Mar 24 at 6:57
You could pipe that command into| xargs printf "%7sn" | tr ' ' 0
â glenn jackman
Mar 24 at 11:10
add a comment |Â
up vote
1
down vote
accepted
Assuming you really mean hex (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) here is a solution up to FF (I don't want to have to count to 4.3 billion):
(echo obase=16; seq 1 $((echo ibase=16; echo FF) | bc)) | bc
The inner
(echo ibase=16; echo FF) | bc
calculates the ending value in decimal (here FF but feel free to substitute FFFFFFFF if you want :-). The seq
then counts from one to 255 in this case, and the rest converts it to hex.
And if you really want base 15, you can change both 16's to 15's (and the FF... to EE...).
This is exactly what I was looking for. How can I make it start at 0000001 instead of 1?
â RainyDay
Mar 24 at 6:57
You could pipe that command into| xargs printf "%7sn" | tr ' ' 0
â glenn jackman
Mar 24 at 11:10
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Assuming you really mean hex (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) here is a solution up to FF (I don't want to have to count to 4.3 billion):
(echo obase=16; seq 1 $((echo ibase=16; echo FF) | bc)) | bc
The inner
(echo ibase=16; echo FF) | bc
calculates the ending value in decimal (here FF but feel free to substitute FFFFFFFF if you want :-). The seq
then counts from one to 255 in this case, and the rest converts it to hex.
And if you really want base 15, you can change both 16's to 15's (and the FF... to EE...).
Assuming you really mean hex (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) here is a solution up to FF (I don't want to have to count to 4.3 billion):
(echo obase=16; seq 1 $((echo ibase=16; echo FF) | bc)) | bc
The inner
(echo ibase=16; echo FF) | bc
calculates the ending value in decimal (here FF but feel free to substitute FFFFFFFF if you want :-). The seq
then counts from one to 255 in this case, and the rest converts it to hex.
And if you really want base 15, you can change both 16's to 15's (and the FF... to EE...).
answered Mar 24 at 4:04
NickD
1,5571312
1,5571312
This is exactly what I was looking for. How can I make it start at 0000001 instead of 1?
â RainyDay
Mar 24 at 6:57
You could pipe that command into| xargs printf "%7sn" | tr ' ' 0
â glenn jackman
Mar 24 at 11:10
add a comment |Â
This is exactly what I was looking for. How can I make it start at 0000001 instead of 1?
â RainyDay
Mar 24 at 6:57
You could pipe that command into| xargs printf "%7sn" | tr ' ' 0
â glenn jackman
Mar 24 at 11:10
This is exactly what I was looking for. How can I make it start at 0000001 instead of 1?
â RainyDay
Mar 24 at 6:57
This is exactly what I was looking for. How can I make it start at 0000001 instead of 1?
â RainyDay
Mar 24 at 6:57
You could pipe that command into
| xargs printf "%7sn" | tr ' ' 0
â glenn jackman
Mar 24 at 11:10
You could pipe that command into
| xargs printf "%7sn" | tr ' ' 0
â glenn jackman
Mar 24 at 11:10
add a comment |Â
up vote
1
down vote
Just play with the print operators
#!/bin/bash
for number in $( seq 1 255 )
do
hex_representation=$( printf "%X" $number )
echo "$number: $hex_representation"
done
2
Or justprintf '%06Xn' $(seq 1 255)
(I added zero padding in line with the OP's desired output format)
â steeldriver
Mar 24 at 11:49
This answer is also a good solution. In the loop how can I control the output? In the loop 0000001 is sent to an empty file like this: printf '%06Xn' $(seq 1 255) > file. Then on second loop cycle 0000002 is sent into the file, etc. Is there a simple way to pause this command until next loop?
â RainyDay
Mar 26 at 3:37
add a comment |Â
up vote
1
down vote
Just play with the print operators
#!/bin/bash
for number in $( seq 1 255 )
do
hex_representation=$( printf "%X" $number )
echo "$number: $hex_representation"
done
2
Or justprintf '%06Xn' $(seq 1 255)
(I added zero padding in line with the OP's desired output format)
â steeldriver
Mar 24 at 11:49
This answer is also a good solution. In the loop how can I control the output? In the loop 0000001 is sent to an empty file like this: printf '%06Xn' $(seq 1 255) > file. Then on second loop cycle 0000002 is sent into the file, etc. Is there a simple way to pause this command until next loop?
â RainyDay
Mar 26 at 3:37
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Just play with the print operators
#!/bin/bash
for number in $( seq 1 255 )
do
hex_representation=$( printf "%X" $number )
echo "$number: $hex_representation"
done
Just play with the print operators
#!/bin/bash
for number in $( seq 1 255 )
do
hex_representation=$( printf "%X" $number )
echo "$number: $hex_representation"
done
answered Mar 24 at 4:04
vfbsilva
2,54211225
2,54211225
2
Or justprintf '%06Xn' $(seq 1 255)
(I added zero padding in line with the OP's desired output format)
â steeldriver
Mar 24 at 11:49
This answer is also a good solution. In the loop how can I control the output? In the loop 0000001 is sent to an empty file like this: printf '%06Xn' $(seq 1 255) > file. Then on second loop cycle 0000002 is sent into the file, etc. Is there a simple way to pause this command until next loop?
â RainyDay
Mar 26 at 3:37
add a comment |Â
2
Or justprintf '%06Xn' $(seq 1 255)
(I added zero padding in line with the OP's desired output format)
â steeldriver
Mar 24 at 11:49
This answer is also a good solution. In the loop how can I control the output? In the loop 0000001 is sent to an empty file like this: printf '%06Xn' $(seq 1 255) > file. Then on second loop cycle 0000002 is sent into the file, etc. Is there a simple way to pause this command until next loop?
â RainyDay
Mar 26 at 3:37
2
2
Or just
printf '%06Xn' $(seq 1 255)
(I added zero padding in line with the OP's desired output format)â steeldriver
Mar 24 at 11:49
Or just
printf '%06Xn' $(seq 1 255)
(I added zero padding in line with the OP's desired output format)â steeldriver
Mar 24 at 11:49
This answer is also a good solution. In the loop how can I control the output? In the loop 0000001 is sent to an empty file like this: printf '%06Xn' $(seq 1 255) > file. Then on second loop cycle 0000002 is sent into the file, etc. Is there a simple way to pause this command until next loop?
â RainyDay
Mar 26 at 3:37
This answer is also a good solution. In the loop how can I control the output? In the loop 0000001 is sent to an empty file like this: printf '%06Xn' $(seq 1 255) > file. Then on second loop cycle 0000002 is sent into the file, etc. Is there a simple way to pause this command until next loop?
â RainyDay
Mar 26 at 3:37
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433197%2fbash-increment-alphanumeric-data-from-command-prompt%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
These are numeric data in hex. They are not arbitrary alphanumeric data.
â NickD
Mar 24 at 3:44
2
I don't see any f in there: are you sure that it should not be there? That would be base 15 numeric data which seems ... strange.
â NickD
Mar 24 at 3:57