Answer the question
In order to leave comments, you need to log in
How to validate in a string?
There is a line:
0000000000000000;39999999999;2;NONE;true;526;246;101;100;2;1;;;;;;8;101/100.000.99.99;246/000.000.122.122
All values can change.
You need to somehow compare the part of the string containing: 526;246;101;100;2;1 with the part of the string containing the values before the slash, i.e. in this case 101 and 246 (piece of the string 101 /100.000.99.99; 246 /000.000.122.122)
And if the first part of the string (526; 246 ; 101 ;100;2;1) has the same values as in the second part of the string 101 and 246 (the part of the string 101 /100.000.99.99; 246 /000.000.122.122 ) remove them from the first chunk of the string.
That is, the output should be in this case the string: 0000000000000000;39999999999;2;NONE;true;526;;;100;2;1;;;;;;8;101/100.000.99.99;246/000.000.122.122
Answer the question
In order to leave comments, you need to log in
The easiest way is probably to use awk to parse the string by the delimiter ";" compare what you need and collect back.
if completely in the forehead:
#!/bin/bash
a="0000000000000000;39999999999;2;NONE;true;526;246;101;100;2;1;;;;;;8;101/100.000.99.99;246/000.000.122.122"
b=`echo $a | awk -F ";" '{print $7"-"$8}'`
c=`echo ${a} | awk -F ";" '{print $18}' | awk -F "/" '{print $1}'`
d=`echo ${a} | awk -F ";" '{print $19}' | awk -F "/" '{print $1}'`
if
then
echo $a | awk -F ";" '{print $1 ";" $2 ";" ";" $3 ";" $4 ";" $5 ";" $6 ";" ";" ";" ";" $9 ";" $10 ";" $11 ";" $12 ";" $13 ";" $14 ";" $15 ";" $16 ";" $17 ";" $18 ";" $19}'
fi
my $str = '0000000000000000;39999999999;2;NONE;true;526;246;101;100;2;1;;;;;;8;101/100.000.99.99;246/000.000.122.122';
#-------------------------------------------------------------------------------
# Заменили дроби на ;
#-------------------------------------------------------------------------------
$str =~ s!/!;!gx;
#-------------------------------------------------------------------------------
# Получили один большой массив
#-------------------------------------------------------------------------------
my (@arr) = split ';', $str;
#-------------------------------------------------------------------------------
# Получаем дубликаты
#-------------------------------------------------------------------------------
my %seen = ();
my @dup = map { 1==$seen{$_}++ ? $_ : () } @arr;
say Dumper @dup;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question