7 td-disamb-headers - Disambiguate headers in tabular data
11 Change column names in input tabular data stream by appending a sequential number
12 to the duplicated column names.
13 The first occurrance is kept as-is.
14 If a particular column name already ends with an integer, it gets incremented.
18 echo "PID PID PID2 PID2 USER CMD" | td-disamb-headers
22 PID PID3 PID2 PID4 USER CMD
27 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
28 do '/usr/lib/tool/perl5/tabdata/common.pl' or die "$@";
31 process_header
(scalar <STDIN
>);
34 for my $colname (@Header)
36 my @other_Columns = grep {$_ ne $colname} @Header;
37 my $new_colname = $colname;
38 while($new_colname ~~ @new_Columns or $new_colname ~~ @other_Columns)
40 # increment trailing counter
41 $new_colname =~ s/(\d*)$/($1 or 1) + 1/e;
43 push @new_Columns, $new_colname;
45 @Header = @new_Columns;
47 print join($FS, @Header).$RS;