Tente algo assim:
#!/usr/bin/gawk -f
{
## Every time we change file, print the data for
## the last file read (ARGV[ARGIND-1])
if(FNR==1 && ARGIND>1){
print "This was the analysis of file:" ARGV[ARGIND-1]
print "The number of lines with >10 characters is:" s,"\n"
s=0;
}
if(length($0)>10){
print "The line number is:" FNR
print "The content of the line is:" substr($0,10)
s=s+1
}
}
## print the data collected on the last file in the list
END{
print "This was the analysis of file:" ARGV[ARGIND]
print "The number of lines with >10 characters is:" s,"\n"
}
Se você executar isso nos arquivos a
, b
e c
:
$ ./foo.awk a b c
The line number is:2
The content of the line is:kldjahlskdjbasd
This was the analysis of the file:a
The number of lines with characters >10 is:1
The line number is:2
The content of the line is:ldjbfskldfbskldjfbsdf
The line number is:3
The content of the line is:kfjbskldjfbskldjfbsdf
The line number is:4
The content of the line is:ldfbskldfbskldfbskldbfs
The line number is:5
The content of the line is:lsjdbfklsdjbfklsjdbfskljdbf
This was the analysis of the file:b
The number of lines with characters >10 is:4
The line number is:1
The content of the line is: asdklfhakldhflaksdhfa
This was the analysis of the file:c
The number of lines with characters >10 is:1