我有这个工作perl可以支持4个十六进制数字交换另一个4个十六进制
perl -wMstrict -le '
my @bits = unpack "(A1)16", sprintf "%016b", hex shift;
my $bitmap = "D5679123C4EF80AB";
@bits = @bits[ map { hex } split //, $bitmap ];
$"="";
print sprintf "%04X", oct "0b@bits";
' "B455"
结果: CB15
请问如何支持128字节以外的更多字节?
以及如何使用这个perl从file.txt中读取十六进制文件?
提前感谢。
答案 0 :(得分:0)
您可以尝试以下方法:
str1='V 12345678Z 12345678N 05 sometext some/t2/text'
if [[ $str1 =~ [0-9]{8}[A-Z]\ ([0-9]{8}[A-Z]) ]]; then
match="${BASH_REMATCH[1]}"
else
match="false"
fi
echo "$match"
<强>输出强>:
use feature qw(say);
use strict;
use warnings;
# Example with 64 bits
my $data = 'B455AB10A1230000'; # original data (64 bits)
my @bits = map { unpack '(A)*', sprintf '%08b', hex } unpack '(A2)*', $data;
my @bitmap = reverse 0..63; # some 64 bits map, replace with your actual data
my $result = unpack "H*", pack 'C*', map { oct "0b$_" } unpack "(A8)*", join '', @bits[@bitmap];
say "Input : $data";
say "Result: $result";