Hexadecimal number sequence checker in Linux?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a list of hexadecimal number. I would like to check whether they are in sequence or not. That is, they should be consecutive numbers, in increasing order. In other words, there should be an increment of 1 from each line to the next.
Sample list of hexadecimal numbers:
85AF
85B0
85B1
85B2
85B3
85B4
85B5
85B6
85B7
85B8
85B9
85BA
85BB
85BC
85BD
85BE
85BF
85C0
In reality I would have more than 500 numbers to check through.
Desired output:
All numbers are in sequence
(or)
Numbers are not in sequence.
This is on Solaris, with ksh.
shell shell-script text-processing ksh arithmetic
add a comment |Â
up vote
1
down vote
favorite
I have a list of hexadecimal number. I would like to check whether they are in sequence or not. That is, they should be consecutive numbers, in increasing order. In other words, there should be an increment of 1 from each line to the next.
Sample list of hexadecimal numbers:
85AF
85B0
85B1
85B2
85B3
85B4
85B5
85B6
85B7
85B8
85B9
85BA
85BB
85BC
85BD
85BE
85BF
85C0
In reality I would have more than 500 numbers to check through.
Desired output:
All numbers are in sequence
(or)
Numbers are not in sequence.
This is on Solaris, with ksh.
shell shell-script text-processing ksh arithmetic
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a list of hexadecimal number. I would like to check whether they are in sequence or not. That is, they should be consecutive numbers, in increasing order. In other words, there should be an increment of 1 from each line to the next.
Sample list of hexadecimal numbers:
85AF
85B0
85B1
85B2
85B3
85B4
85B5
85B6
85B7
85B8
85B9
85BA
85BB
85BC
85BD
85BE
85BF
85C0
In reality I would have more than 500 numbers to check through.
Desired output:
All numbers are in sequence
(or)
Numbers are not in sequence.
This is on Solaris, with ksh.
shell shell-script text-processing ksh arithmetic
I have a list of hexadecimal number. I would like to check whether they are in sequence or not. That is, they should be consecutive numbers, in increasing order. In other words, there should be an increment of 1 from each line to the next.
Sample list of hexadecimal numbers:
85AF
85B0
85B1
85B2
85B3
85B4
85B5
85B6
85B7
85B8
85B9
85BA
85BB
85BC
85BD
85BE
85BF
85C0
In reality I would have more than 500 numbers to check through.
Desired output:
All numbers are in sequence
(or)
Numbers are not in sequence.
This is on Solaris, with ksh.
shell shell-script text-processing ksh arithmetic
shell shell-script text-processing ksh arithmetic
edited May 18 '15 at 20:51
Gilles
512k12010151547
512k12010151547
asked May 18 '15 at 17:18
ayrton_senna
5072418
5072418
add a comment |Â
add a comment |Â
6 Answers
6
active
oldest
votes
up vote
2
down vote
Awk could do this easily if the output was in decimal, but it can't parse hexadecimal numbers (at least standard awk can't, some versions such as GNU awk can). You can use bc
to do the conversion. This works on all POSIX systems.
echo "ibase=16"; cat input.txt; | bc |
awk 'NR==1 origin = $0-1
$0!=origin+NR print "Out-of-sequence number at line", NR; exit(1)' >&2
add a comment |Â
up vote
2
down vote
As said in another answer, it would be nice to do this in awk, but ancient awk (the one probably available in Solaris) doesn't understand hex numbers.
A fast solution is to use wc -l
and some ksh math:
#! /bin/ksh
first="0x$(head -n1 infile)"
last="0x$(tail -n1 infile)"
lines=$(wc -l <infile)
if [[ "$(( last - first + 1 - lines ))" -eq 0 ]]; then
echo "All numbers are in sequence."
else
echo "Numbers are not in sequence."
fi
add a comment |Â
up vote
1
down vote
Here is one option:
while read x; do echo $((16#$x)); done <yourfile | awk 's && $1!=s+1exit(1)s=$1'
This shell command will produce an exit status of 1 (on fail) and 0 (on success). This command can be used e.g. in an if-clause like the following to produce the desired output:
if while read x; do echo $((16#$x)); done < yourfile | awk 's && $1!=s+1exit(1)s=$1'
then echo All numbers are in sequence
else echo Numbers are not in sequence
fi
(Note that you have you substitute the name "yourfile" by the file name that contains your hex number sequence.)
You can also omit the shell loop and use GNU awk
's option -n
to process the hex numbers directly:
if sed 's/^/0x/' <yourfile | awk -n 's && $1+0!=s+1exit(1)s=$1+0'
then echo All numbers are in sequence
else echo Numbers are not in sequence.
fi
Note: sed is used here to create the syntactically expected format for the hex numbers (with leading 0x
).
this method seems to be nice. But i can not put it in a script. awk is bailing out with a syntax error. Can you provide me the .KSH file.
â ayrton_senna
May 18 '15 at 18:46
Which of the two versions are you trying? And are you working on solaris? - In the latter case see whether you have a GNUawk
installed. Or else try the first version with/usr/xpg4/bin/awk
(instead of the defaultawk
). - WRT the requested "ksh
file"; you would just copy/paste the posted code in a filetesthexseq
(don't forget to adjust the name of the hex source file), and call it asksh testhexseq
.
â Janis
May 18 '15 at 18:48
add a comment |Â
up vote
0
down vote
You can use sort
with the option -c
to check if the input data is sorted:
-c
Check that the single input file is ordered as specified by the arguments and
the collating sequence of the current locale. Output
shall not be sent to standard output. The exit code shall indicate
whether or not disorder was detected or an error occurred. If
disorder (or, with -u, a duplicate key) is detected, a warning
message shall be sent to standard error indicating where the disorder
or duplicate key was found.
So a simple
LC_ALL=C
sort -c data 2> /dev/null
&& echo All numbers are in sequence
|| echo Numbers are not in sequence
would do.
Do not work with trailing empty lines. Just remove it and use<(sed '/S/!d' data)
insteaddata
â Costas
May 18 '15 at 19:26
@Costas OP doesn't say anything about trailing lines.
â FloHimself
May 18 '15 at 19:31
This doesn't check that the increment is 1 (as clarified in a comment prior to your answer).
â Gilles
May 18 '15 at 20:51
This wasn't a requirement in OP before your edit.
â FloHimself
May 19 '15 at 4:58
add a comment |Â
up vote
0
down vote
If you'd like strict sequence it can be easy done by produce etalon sequence and compare it with file
[ $(comm --nocheck-order -3
<(sed '/S/!d' file)
<(printf "%Xn"
$(seq $((16#$(sed '/./!d;q' file)))
$((16#$(tac file|sed '/./!d;q')))))) ] &&
echo 'Numbers are not in sequence' ||
echo 'All numbers are in sequence'
Just to check if all numbers are hexadecimal:
sed '/^[[:xdigit:] ]*$/!
s/.*/Numbers are not in sequence: &/
q
$! d
s/.*/All numbers are in sequence/' hexadecimal_number.list
/^[[:xdigit:] ]*$/
check if in line there are hexadecimal symbols and space only (or nothing - empty line)!
reverse match, so execute commands injust if there some other symbols than described above
s/.*/.../;q
s
ubstitute all line byNumbers are not in sequence
thanq
uit script with printing line$! d
if script didn't execute previous (pattern match) and if line is not lastd
elete it it start with next lines/.*/.../
if script reach last line (so all lines match pattern)s
ubstitute last line byAll numbers are in sequence
an print it
should i put this in a script and run it or its a single line command? i am newbie, sorry for my ignorance.
â ayrton_senna
May 18 '15 at 18:02
@ayrton_senna; Typically longer commands are put in a file (sayyourscript
) and executed by calling the file with a shell (e.g.bash yourscript
). - But in this case I don't see that this code works - it certainly doesn't work when I tried - nor do I see how it would do the desired task. (Costas may want to explain it.)
â Janis
May 18 '15 at 18:17
@ayrton_senna Up to you. It can be used in all variants.
â Costas
May 18 '15 at 18:18
@Janis I have tested - it work
â Costas
May 18 '15 at 18:21
@Costas; If I remove one of the lines in the data file, or add a data element AAAA - in both cases disturbing the order -, I still get a positive result, even though it shouldn't. - Are you sure you tested those cases?
â Janis
May 18 '15 at 18:33
 |Â
show 3 more comments
up vote
0
down vote
Given the input file hexlist.txt, this works in ksh
and bash
. It uses the numinterval
util. If numinterval
isn't available, uncomment the faker function:
# fake `numinterval` function
# numinterval() dc ;
n=; eval printf '%s\n' $(printf '$((16#%sn)) ' $(<hexlist.txt)) |
numinterval | grep -qw 1 || n=not ; echo All numbers are $n in sequence
add a comment |Â
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Awk could do this easily if the output was in decimal, but it can't parse hexadecimal numbers (at least standard awk can't, some versions such as GNU awk can). You can use bc
to do the conversion. This works on all POSIX systems.
echo "ibase=16"; cat input.txt; | bc |
awk 'NR==1 origin = $0-1
$0!=origin+NR print "Out-of-sequence number at line", NR; exit(1)' >&2
add a comment |Â
up vote
2
down vote
Awk could do this easily if the output was in decimal, but it can't parse hexadecimal numbers (at least standard awk can't, some versions such as GNU awk can). You can use bc
to do the conversion. This works on all POSIX systems.
echo "ibase=16"; cat input.txt; | bc |
awk 'NR==1 origin = $0-1
$0!=origin+NR print "Out-of-sequence number at line", NR; exit(1)' >&2
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Awk could do this easily if the output was in decimal, but it can't parse hexadecimal numbers (at least standard awk can't, some versions such as GNU awk can). You can use bc
to do the conversion. This works on all POSIX systems.
echo "ibase=16"; cat input.txt; | bc |
awk 'NR==1 origin = $0-1
$0!=origin+NR print "Out-of-sequence number at line", NR; exit(1)' >&2
Awk could do this easily if the output was in decimal, but it can't parse hexadecimal numbers (at least standard awk can't, some versions such as GNU awk can). You can use bc
to do the conversion. This works on all POSIX systems.
echo "ibase=16"; cat input.txt; | bc |
awk 'NR==1 origin = $0-1
$0!=origin+NR print "Out-of-sequence number at line", NR; exit(1)' >&2
answered May 18 '15 at 23:30
Gilles
512k12010151547
512k12010151547
add a comment |Â
add a comment |Â
up vote
2
down vote
As said in another answer, it would be nice to do this in awk, but ancient awk (the one probably available in Solaris) doesn't understand hex numbers.
A fast solution is to use wc -l
and some ksh math:
#! /bin/ksh
first="0x$(head -n1 infile)"
last="0x$(tail -n1 infile)"
lines=$(wc -l <infile)
if [[ "$(( last - first + 1 - lines ))" -eq 0 ]]; then
echo "All numbers are in sequence."
else
echo "Numbers are not in sequence."
fi
add a comment |Â
up vote
2
down vote
As said in another answer, it would be nice to do this in awk, but ancient awk (the one probably available in Solaris) doesn't understand hex numbers.
A fast solution is to use wc -l
and some ksh math:
#! /bin/ksh
first="0x$(head -n1 infile)"
last="0x$(tail -n1 infile)"
lines=$(wc -l <infile)
if [[ "$(( last - first + 1 - lines ))" -eq 0 ]]; then
echo "All numbers are in sequence."
else
echo "Numbers are not in sequence."
fi
add a comment |Â
up vote
2
down vote
up vote
2
down vote
As said in another answer, it would be nice to do this in awk, but ancient awk (the one probably available in Solaris) doesn't understand hex numbers.
A fast solution is to use wc -l
and some ksh math:
#! /bin/ksh
first="0x$(head -n1 infile)"
last="0x$(tail -n1 infile)"
lines=$(wc -l <infile)
if [[ "$(( last - first + 1 - lines ))" -eq 0 ]]; then
echo "All numbers are in sequence."
else
echo "Numbers are not in sequence."
fi
As said in another answer, it would be nice to do this in awk, but ancient awk (the one probably available in Solaris) doesn't understand hex numbers.
A fast solution is to use wc -l
and some ksh math:
#! /bin/ksh
first="0x$(head -n1 infile)"
last="0x$(tail -n1 infile)"
lines=$(wc -l <infile)
if [[ "$(( last - first + 1 - lines ))" -eq 0 ]]; then
echo "All numbers are in sequence."
else
echo "Numbers are not in sequence."
fi
answered Sep 28 at 1:40
Isaac
7,60511137
7,60511137
add a comment |Â
add a comment |Â
up vote
1
down vote
Here is one option:
while read x; do echo $((16#$x)); done <yourfile | awk 's && $1!=s+1exit(1)s=$1'
This shell command will produce an exit status of 1 (on fail) and 0 (on success). This command can be used e.g. in an if-clause like the following to produce the desired output:
if while read x; do echo $((16#$x)); done < yourfile | awk 's && $1!=s+1exit(1)s=$1'
then echo All numbers are in sequence
else echo Numbers are not in sequence
fi
(Note that you have you substitute the name "yourfile" by the file name that contains your hex number sequence.)
You can also omit the shell loop and use GNU awk
's option -n
to process the hex numbers directly:
if sed 's/^/0x/' <yourfile | awk -n 's && $1+0!=s+1exit(1)s=$1+0'
then echo All numbers are in sequence
else echo Numbers are not in sequence.
fi
Note: sed is used here to create the syntactically expected format for the hex numbers (with leading 0x
).
this method seems to be nice. But i can not put it in a script. awk is bailing out with a syntax error. Can you provide me the .KSH file.
â ayrton_senna
May 18 '15 at 18:46
Which of the two versions are you trying? And are you working on solaris? - In the latter case see whether you have a GNUawk
installed. Or else try the first version with/usr/xpg4/bin/awk
(instead of the defaultawk
). - WRT the requested "ksh
file"; you would just copy/paste the posted code in a filetesthexseq
(don't forget to adjust the name of the hex source file), and call it asksh testhexseq
.
â Janis
May 18 '15 at 18:48
add a comment |Â
up vote
1
down vote
Here is one option:
while read x; do echo $((16#$x)); done <yourfile | awk 's && $1!=s+1exit(1)s=$1'
This shell command will produce an exit status of 1 (on fail) and 0 (on success). This command can be used e.g. in an if-clause like the following to produce the desired output:
if while read x; do echo $((16#$x)); done < yourfile | awk 's && $1!=s+1exit(1)s=$1'
then echo All numbers are in sequence
else echo Numbers are not in sequence
fi
(Note that you have you substitute the name "yourfile" by the file name that contains your hex number sequence.)
You can also omit the shell loop and use GNU awk
's option -n
to process the hex numbers directly:
if sed 's/^/0x/' <yourfile | awk -n 's && $1+0!=s+1exit(1)s=$1+0'
then echo All numbers are in sequence
else echo Numbers are not in sequence.
fi
Note: sed is used here to create the syntactically expected format for the hex numbers (with leading 0x
).
this method seems to be nice. But i can not put it in a script. awk is bailing out with a syntax error. Can you provide me the .KSH file.
â ayrton_senna
May 18 '15 at 18:46
Which of the two versions are you trying? And are you working on solaris? - In the latter case see whether you have a GNUawk
installed. Or else try the first version with/usr/xpg4/bin/awk
(instead of the defaultawk
). - WRT the requested "ksh
file"; you would just copy/paste the posted code in a filetesthexseq
(don't forget to adjust the name of the hex source file), and call it asksh testhexseq
.
â Janis
May 18 '15 at 18:48
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Here is one option:
while read x; do echo $((16#$x)); done <yourfile | awk 's && $1!=s+1exit(1)s=$1'
This shell command will produce an exit status of 1 (on fail) and 0 (on success). This command can be used e.g. in an if-clause like the following to produce the desired output:
if while read x; do echo $((16#$x)); done < yourfile | awk 's && $1!=s+1exit(1)s=$1'
then echo All numbers are in sequence
else echo Numbers are not in sequence
fi
(Note that you have you substitute the name "yourfile" by the file name that contains your hex number sequence.)
You can also omit the shell loop and use GNU awk
's option -n
to process the hex numbers directly:
if sed 's/^/0x/' <yourfile | awk -n 's && $1+0!=s+1exit(1)s=$1+0'
then echo All numbers are in sequence
else echo Numbers are not in sequence.
fi
Note: sed is used here to create the syntactically expected format for the hex numbers (with leading 0x
).
Here is one option:
while read x; do echo $((16#$x)); done <yourfile | awk 's && $1!=s+1exit(1)s=$1'
This shell command will produce an exit status of 1 (on fail) and 0 (on success). This command can be used e.g. in an if-clause like the following to produce the desired output:
if while read x; do echo $((16#$x)); done < yourfile | awk 's && $1!=s+1exit(1)s=$1'
then echo All numbers are in sequence
else echo Numbers are not in sequence
fi
(Note that you have you substitute the name "yourfile" by the file name that contains your hex number sequence.)
You can also omit the shell loop and use GNU awk
's option -n
to process the hex numbers directly:
if sed 's/^/0x/' <yourfile | awk -n 's && $1+0!=s+1exit(1)s=$1+0'
then echo All numbers are in sequence
else echo Numbers are not in sequence.
fi
Note: sed is used here to create the syntactically expected format for the hex numbers (with leading 0x
).
edited May 18 '15 at 18:29
answered May 18 '15 at 18:14
Janis
9,81011236
9,81011236
this method seems to be nice. But i can not put it in a script. awk is bailing out with a syntax error. Can you provide me the .KSH file.
â ayrton_senna
May 18 '15 at 18:46
Which of the two versions are you trying? And are you working on solaris? - In the latter case see whether you have a GNUawk
installed. Or else try the first version with/usr/xpg4/bin/awk
(instead of the defaultawk
). - WRT the requested "ksh
file"; you would just copy/paste the posted code in a filetesthexseq
(don't forget to adjust the name of the hex source file), and call it asksh testhexseq
.
â Janis
May 18 '15 at 18:48
add a comment |Â
this method seems to be nice. But i can not put it in a script. awk is bailing out with a syntax error. Can you provide me the .KSH file.
â ayrton_senna
May 18 '15 at 18:46
Which of the two versions are you trying? And are you working on solaris? - In the latter case see whether you have a GNUawk
installed. Or else try the first version with/usr/xpg4/bin/awk
(instead of the defaultawk
). - WRT the requested "ksh
file"; you would just copy/paste the posted code in a filetesthexseq
(don't forget to adjust the name of the hex source file), and call it asksh testhexseq
.
â Janis
May 18 '15 at 18:48
this method seems to be nice. But i can not put it in a script. awk is bailing out with a syntax error. Can you provide me the .KSH file.
â ayrton_senna
May 18 '15 at 18:46
this method seems to be nice. But i can not put it in a script. awk is bailing out with a syntax error. Can you provide me the .KSH file.
â ayrton_senna
May 18 '15 at 18:46
Which of the two versions are you trying? And are you working on solaris? - In the latter case see whether you have a GNU
awk
installed. Or else try the first version with /usr/xpg4/bin/awk
(instead of the default awk
). - WRT the requested "ksh
file"; you would just copy/paste the posted code in a file testhexseq
(don't forget to adjust the name of the hex source file), and call it as ksh testhexseq
.â Janis
May 18 '15 at 18:48
Which of the two versions are you trying? And are you working on solaris? - In the latter case see whether you have a GNU
awk
installed. Or else try the first version with /usr/xpg4/bin/awk
(instead of the default awk
). - WRT the requested "ksh
file"; you would just copy/paste the posted code in a file testhexseq
(don't forget to adjust the name of the hex source file), and call it as ksh testhexseq
.â Janis
May 18 '15 at 18:48
add a comment |Â
up vote
0
down vote
You can use sort
with the option -c
to check if the input data is sorted:
-c
Check that the single input file is ordered as specified by the arguments and
the collating sequence of the current locale. Output
shall not be sent to standard output. The exit code shall indicate
whether or not disorder was detected or an error occurred. If
disorder (or, with -u, a duplicate key) is detected, a warning
message shall be sent to standard error indicating where the disorder
or duplicate key was found.
So a simple
LC_ALL=C
sort -c data 2> /dev/null
&& echo All numbers are in sequence
|| echo Numbers are not in sequence
would do.
Do not work with trailing empty lines. Just remove it and use<(sed '/S/!d' data)
insteaddata
â Costas
May 18 '15 at 19:26
@Costas OP doesn't say anything about trailing lines.
â FloHimself
May 18 '15 at 19:31
This doesn't check that the increment is 1 (as clarified in a comment prior to your answer).
â Gilles
May 18 '15 at 20:51
This wasn't a requirement in OP before your edit.
â FloHimself
May 19 '15 at 4:58
add a comment |Â
up vote
0
down vote
You can use sort
with the option -c
to check if the input data is sorted:
-c
Check that the single input file is ordered as specified by the arguments and
the collating sequence of the current locale. Output
shall not be sent to standard output. The exit code shall indicate
whether or not disorder was detected or an error occurred. If
disorder (or, with -u, a duplicate key) is detected, a warning
message shall be sent to standard error indicating where the disorder
or duplicate key was found.
So a simple
LC_ALL=C
sort -c data 2> /dev/null
&& echo All numbers are in sequence
|| echo Numbers are not in sequence
would do.
Do not work with trailing empty lines. Just remove it and use<(sed '/S/!d' data)
insteaddata
â Costas
May 18 '15 at 19:26
@Costas OP doesn't say anything about trailing lines.
â FloHimself
May 18 '15 at 19:31
This doesn't check that the increment is 1 (as clarified in a comment prior to your answer).
â Gilles
May 18 '15 at 20:51
This wasn't a requirement in OP before your edit.
â FloHimself
May 19 '15 at 4:58
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You can use sort
with the option -c
to check if the input data is sorted:
-c
Check that the single input file is ordered as specified by the arguments and
the collating sequence of the current locale. Output
shall not be sent to standard output. The exit code shall indicate
whether or not disorder was detected or an error occurred. If
disorder (or, with -u, a duplicate key) is detected, a warning
message shall be sent to standard error indicating where the disorder
or duplicate key was found.
So a simple
LC_ALL=C
sort -c data 2> /dev/null
&& echo All numbers are in sequence
|| echo Numbers are not in sequence
would do.
You can use sort
with the option -c
to check if the input data is sorted:
-c
Check that the single input file is ordered as specified by the arguments and
the collating sequence of the current locale. Output
shall not be sent to standard output. The exit code shall indicate
whether or not disorder was detected or an error occurred. If
disorder (or, with -u, a duplicate key) is detected, a warning
message shall be sent to standard error indicating where the disorder
or duplicate key was found.
So a simple
LC_ALL=C
sort -c data 2> /dev/null
&& echo All numbers are in sequence
|| echo Numbers are not in sequence
would do.
answered May 18 '15 at 19:01
FloHimself
6,01421318
6,01421318
Do not work with trailing empty lines. Just remove it and use<(sed '/S/!d' data)
insteaddata
â Costas
May 18 '15 at 19:26
@Costas OP doesn't say anything about trailing lines.
â FloHimself
May 18 '15 at 19:31
This doesn't check that the increment is 1 (as clarified in a comment prior to your answer).
â Gilles
May 18 '15 at 20:51
This wasn't a requirement in OP before your edit.
â FloHimself
May 19 '15 at 4:58
add a comment |Â
Do not work with trailing empty lines. Just remove it and use<(sed '/S/!d' data)
insteaddata
â Costas
May 18 '15 at 19:26
@Costas OP doesn't say anything about trailing lines.
â FloHimself
May 18 '15 at 19:31
This doesn't check that the increment is 1 (as clarified in a comment prior to your answer).
â Gilles
May 18 '15 at 20:51
This wasn't a requirement in OP before your edit.
â FloHimself
May 19 '15 at 4:58
Do not work with trailing empty lines. Just remove it and use
<(sed '/S/!d' data)
instead data
â Costas
May 18 '15 at 19:26
Do not work with trailing empty lines. Just remove it and use
<(sed '/S/!d' data)
instead data
â Costas
May 18 '15 at 19:26
@Costas OP doesn't say anything about trailing lines.
â FloHimself
May 18 '15 at 19:31
@Costas OP doesn't say anything about trailing lines.
â FloHimself
May 18 '15 at 19:31
This doesn't check that the increment is 1 (as clarified in a comment prior to your answer).
â Gilles
May 18 '15 at 20:51
This doesn't check that the increment is 1 (as clarified in a comment prior to your answer).
â Gilles
May 18 '15 at 20:51
This wasn't a requirement in OP before your edit.
â FloHimself
May 19 '15 at 4:58
This wasn't a requirement in OP before your edit.
â FloHimself
May 19 '15 at 4:58
add a comment |Â
up vote
0
down vote
If you'd like strict sequence it can be easy done by produce etalon sequence and compare it with file
[ $(comm --nocheck-order -3
<(sed '/S/!d' file)
<(printf "%Xn"
$(seq $((16#$(sed '/./!d;q' file)))
$((16#$(tac file|sed '/./!d;q')))))) ] &&
echo 'Numbers are not in sequence' ||
echo 'All numbers are in sequence'
Just to check if all numbers are hexadecimal:
sed '/^[[:xdigit:] ]*$/!
s/.*/Numbers are not in sequence: &/
q
$! d
s/.*/All numbers are in sequence/' hexadecimal_number.list
/^[[:xdigit:] ]*$/
check if in line there are hexadecimal symbols and space only (or nothing - empty line)!
reverse match, so execute commands injust if there some other symbols than described above
s/.*/.../;q
s
ubstitute all line byNumbers are not in sequence
thanq
uit script with printing line$! d
if script didn't execute previous (pattern match) and if line is not lastd
elete it it start with next lines/.*/.../
if script reach last line (so all lines match pattern)s
ubstitute last line byAll numbers are in sequence
an print it
should i put this in a script and run it or its a single line command? i am newbie, sorry for my ignorance.
â ayrton_senna
May 18 '15 at 18:02
@ayrton_senna; Typically longer commands are put in a file (sayyourscript
) and executed by calling the file with a shell (e.g.bash yourscript
). - But in this case I don't see that this code works - it certainly doesn't work when I tried - nor do I see how it would do the desired task. (Costas may want to explain it.)
â Janis
May 18 '15 at 18:17
@ayrton_senna Up to you. It can be used in all variants.
â Costas
May 18 '15 at 18:18
@Janis I have tested - it work
â Costas
May 18 '15 at 18:21
@Costas; If I remove one of the lines in the data file, or add a data element AAAA - in both cases disturbing the order -, I still get a positive result, even though it shouldn't. - Are you sure you tested those cases?
â Janis
May 18 '15 at 18:33
 |Â
show 3 more comments
up vote
0
down vote
If you'd like strict sequence it can be easy done by produce etalon sequence and compare it with file
[ $(comm --nocheck-order -3
<(sed '/S/!d' file)
<(printf "%Xn"
$(seq $((16#$(sed '/./!d;q' file)))
$((16#$(tac file|sed '/./!d;q')))))) ] &&
echo 'Numbers are not in sequence' ||
echo 'All numbers are in sequence'
Just to check if all numbers are hexadecimal:
sed '/^[[:xdigit:] ]*$/!
s/.*/Numbers are not in sequence: &/
q
$! d
s/.*/All numbers are in sequence/' hexadecimal_number.list
/^[[:xdigit:] ]*$/
check if in line there are hexadecimal symbols and space only (or nothing - empty line)!
reverse match, so execute commands injust if there some other symbols than described above
s/.*/.../;q
s
ubstitute all line byNumbers are not in sequence
thanq
uit script with printing line$! d
if script didn't execute previous (pattern match) and if line is not lastd
elete it it start with next lines/.*/.../
if script reach last line (so all lines match pattern)s
ubstitute last line byAll numbers are in sequence
an print it
should i put this in a script and run it or its a single line command? i am newbie, sorry for my ignorance.
â ayrton_senna
May 18 '15 at 18:02
@ayrton_senna; Typically longer commands are put in a file (sayyourscript
) and executed by calling the file with a shell (e.g.bash yourscript
). - But in this case I don't see that this code works - it certainly doesn't work when I tried - nor do I see how it would do the desired task. (Costas may want to explain it.)
â Janis
May 18 '15 at 18:17
@ayrton_senna Up to you. It can be used in all variants.
â Costas
May 18 '15 at 18:18
@Janis I have tested - it work
â Costas
May 18 '15 at 18:21
@Costas; If I remove one of the lines in the data file, or add a data element AAAA - in both cases disturbing the order -, I still get a positive result, even though it shouldn't. - Are you sure you tested those cases?
â Janis
May 18 '15 at 18:33
 |Â
show 3 more comments
up vote
0
down vote
up vote
0
down vote
If you'd like strict sequence it can be easy done by produce etalon sequence and compare it with file
[ $(comm --nocheck-order -3
<(sed '/S/!d' file)
<(printf "%Xn"
$(seq $((16#$(sed '/./!d;q' file)))
$((16#$(tac file|sed '/./!d;q')))))) ] &&
echo 'Numbers are not in sequence' ||
echo 'All numbers are in sequence'
Just to check if all numbers are hexadecimal:
sed '/^[[:xdigit:] ]*$/!
s/.*/Numbers are not in sequence: &/
q
$! d
s/.*/All numbers are in sequence/' hexadecimal_number.list
/^[[:xdigit:] ]*$/
check if in line there are hexadecimal symbols and space only (or nothing - empty line)!
reverse match, so execute commands injust if there some other symbols than described above
s/.*/.../;q
s
ubstitute all line byNumbers are not in sequence
thanq
uit script with printing line$! d
if script didn't execute previous (pattern match) and if line is not lastd
elete it it start with next lines/.*/.../
if script reach last line (so all lines match pattern)s
ubstitute last line byAll numbers are in sequence
an print it
If you'd like strict sequence it can be easy done by produce etalon sequence and compare it with file
[ $(comm --nocheck-order -3
<(sed '/S/!d' file)
<(printf "%Xn"
$(seq $((16#$(sed '/./!d;q' file)))
$((16#$(tac file|sed '/./!d;q')))))) ] &&
echo 'Numbers are not in sequence' ||
echo 'All numbers are in sequence'
Just to check if all numbers are hexadecimal:
sed '/^[[:xdigit:] ]*$/!
s/.*/Numbers are not in sequence: &/
q
$! d
s/.*/All numbers are in sequence/' hexadecimal_number.list
/^[[:xdigit:] ]*$/
check if in line there are hexadecimal symbols and space only (or nothing - empty line)!
reverse match, so execute commands injust if there some other symbols than described above
s/.*/.../;q
s
ubstitute all line byNumbers are not in sequence
thanq
uit script with printing line$! d
if script didn't execute previous (pattern match) and if line is not lastd
elete it it start with next lines/.*/.../
if script reach last line (so all lines match pattern)s
ubstitute last line byAll numbers are in sequence
an print it
edited May 18 '15 at 19:18
answered May 18 '15 at 17:48
Costas
12.5k1029
12.5k1029
should i put this in a script and run it or its a single line command? i am newbie, sorry for my ignorance.
â ayrton_senna
May 18 '15 at 18:02
@ayrton_senna; Typically longer commands are put in a file (sayyourscript
) and executed by calling the file with a shell (e.g.bash yourscript
). - But in this case I don't see that this code works - it certainly doesn't work when I tried - nor do I see how it would do the desired task. (Costas may want to explain it.)
â Janis
May 18 '15 at 18:17
@ayrton_senna Up to you. It can be used in all variants.
â Costas
May 18 '15 at 18:18
@Janis I have tested - it work
â Costas
May 18 '15 at 18:21
@Costas; If I remove one of the lines in the data file, or add a data element AAAA - in both cases disturbing the order -, I still get a positive result, even though it shouldn't. - Are you sure you tested those cases?
â Janis
May 18 '15 at 18:33
 |Â
show 3 more comments
should i put this in a script and run it or its a single line command? i am newbie, sorry for my ignorance.
â ayrton_senna
May 18 '15 at 18:02
@ayrton_senna; Typically longer commands are put in a file (sayyourscript
) and executed by calling the file with a shell (e.g.bash yourscript
). - But in this case I don't see that this code works - it certainly doesn't work when I tried - nor do I see how it would do the desired task. (Costas may want to explain it.)
â Janis
May 18 '15 at 18:17
@ayrton_senna Up to you. It can be used in all variants.
â Costas
May 18 '15 at 18:18
@Janis I have tested - it work
â Costas
May 18 '15 at 18:21
@Costas; If I remove one of the lines in the data file, or add a data element AAAA - in both cases disturbing the order -, I still get a positive result, even though it shouldn't. - Are you sure you tested those cases?
â Janis
May 18 '15 at 18:33
should i put this in a script and run it or its a single line command? i am newbie, sorry for my ignorance.
â ayrton_senna
May 18 '15 at 18:02
should i put this in a script and run it or its a single line command? i am newbie, sorry for my ignorance.
â ayrton_senna
May 18 '15 at 18:02
@ayrton_senna; Typically longer commands are put in a file (say
yourscript
) and executed by calling the file with a shell (e.g. bash yourscript
). - But in this case I don't see that this code works - it certainly doesn't work when I tried - nor do I see how it would do the desired task. (Costas may want to explain it.)â Janis
May 18 '15 at 18:17
@ayrton_senna; Typically longer commands are put in a file (say
yourscript
) and executed by calling the file with a shell (e.g. bash yourscript
). - But in this case I don't see that this code works - it certainly doesn't work when I tried - nor do I see how it would do the desired task. (Costas may want to explain it.)â Janis
May 18 '15 at 18:17
@ayrton_senna Up to you. It can be used in all variants.
â Costas
May 18 '15 at 18:18
@ayrton_senna Up to you. It can be used in all variants.
â Costas
May 18 '15 at 18:18
@Janis I have tested - it work
â Costas
May 18 '15 at 18:21
@Janis I have tested - it work
â Costas
May 18 '15 at 18:21
@Costas; If I remove one of the lines in the data file, or add a data element AAAA - in both cases disturbing the order -, I still get a positive result, even though it shouldn't. - Are you sure you tested those cases?
â Janis
May 18 '15 at 18:33
@Costas; If I remove one of the lines in the data file, or add a data element AAAA - in both cases disturbing the order -, I still get a positive result, even though it shouldn't. - Are you sure you tested those cases?
â Janis
May 18 '15 at 18:33
 |Â
show 3 more comments
up vote
0
down vote
Given the input file hexlist.txt, this works in ksh
and bash
. It uses the numinterval
util. If numinterval
isn't available, uncomment the faker function:
# fake `numinterval` function
# numinterval() dc ;
n=; eval printf '%s\n' $(printf '$((16#%sn)) ' $(<hexlist.txt)) |
numinterval | grep -qw 1 || n=not ; echo All numbers are $n in sequence
add a comment |Â
up vote
0
down vote
Given the input file hexlist.txt, this works in ksh
and bash
. It uses the numinterval
util. If numinterval
isn't available, uncomment the faker function:
# fake `numinterval` function
# numinterval() dc ;
n=; eval printf '%s\n' $(printf '$((16#%sn)) ' $(<hexlist.txt)) |
numinterval | grep -qw 1 || n=not ; echo All numbers are $n in sequence
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Given the input file hexlist.txt, this works in ksh
and bash
. It uses the numinterval
util. If numinterval
isn't available, uncomment the faker function:
# fake `numinterval` function
# numinterval() dc ;
n=; eval printf '%s\n' $(printf '$((16#%sn)) ' $(<hexlist.txt)) |
numinterval | grep -qw 1 || n=not ; echo All numbers are $n in sequence
Given the input file hexlist.txt, this works in ksh
and bash
. It uses the numinterval
util. If numinterval
isn't available, uncomment the faker function:
# fake `numinterval` function
# numinterval() dc ;
n=; eval printf '%s\n' $(printf '$((16#%sn)) ' $(<hexlist.txt)) |
numinterval | grep -qw 1 || n=not ; echo All numbers are $n in sequence
answered Sep 27 at 20:22
agc
4,3221935
4,3221935
add a comment |Â
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%2f204138%2fhexadecimal-number-sequence-checker-in-linux%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