I am working on the anonymisation of several fields in a semicolon-separated text file.
For now I have the following command:
perl -aF'(;)' -ne "s/^.{$length}/$x_string/ for @F[2*$index]; print @F" file
Where $index
corresponds to the index of the string I want to substitute relatively to the semicolon split, $length
is the size of the string to substitute and $x_string
is a simple string of X's.
For an $index
equal to 1
, $size
equal to 3
and $x_string
equal to XXX
, if file
has the following content:
azerty;012;test;20181201;;wxc;
ytreza;345;demo;20160214;;nbv;
Then the perl
command returns this:
azerty;XXX;test;20181201;;wxc;
ytreza;XXX;demo;20160214;;nbv;
My problem is that I want to skip and not to anonymise a potential header line. I know how to do it without the for
statement - using unless $. == 1
for example - but I don't know how to manage it when combined with the -F
option.
Note that I will always have an array of size 1 because of my configuration file's structure pairing the index
and length
variables.
I am a total newbie with perl
so I am asking you for some help with this issue!