i need replace the slash (/) with a newline (\n) and a tab (\t).
With 'find -type f' in a folder i got this output:
./1999/01/file1
./1999/01/file2
./1999/02/file1
./2000/04/file1
./2000/04/file2
./2000/04/file3
./2000/04/file4
./2000/06/file1
./2000/06/file2
./2000/06/file3
./2000/06/file4
If the element a[$2] of the array exists (not a new year) and the 3th field (number) is equal to the value of the element of the array (not a new number) print 2 tabs before the 4th field (filename)
If the element a[$2] of the array exists (not a new year) and the 3th field (number) is not equal to the value of the element of the array (we have a new number!), assign the value of the 3th field (number) to the element a[$2], print 1 one tab before the 3th field (number) and 2 tabs before the 4th field (filename) on separate lines
If the array a[$2] doesn't exist (we have a new year!) assign the value of the 3th field (number) to the element a[$2], print the 2nd field (year), one tab before the 3th field (number) and 2 tabs before the 4th field (filename) on separate lines
i read a introduction to awk and think i got the most of this code, but i have few question to the arrays.
From where come from, are they filled automaticly like $0 with the whole line? What is in there?
use strict;
my ($n,$ind,%hash,%hash2)=(1,5);
open FH,"<a.txt";
while(<FH>){
my @tmp=split("/",$_);
if (not exists $hash2{$tmp[0]}){
$hash2{$tmp[0]}->{SEQ}=$n;
$n++;
}
$hash{$tmp[0]}->{$tmp[1]}.=" " x (2*$ind).$tmp[2];
}
close FH;
for my $out_key (sort {$hash2{$a} <=> $hash2{$b} } keys %hash){
print $out_key,"\n";
my %h = %{$hash{$out_key}};
for my $in_key (sort keys %h){
print " " x $ind;
print $in_key,"\n";
print $h{$in_key};
}
}