Trying to solve this question append wc... I cannot understand how to catch filename passed as argument to awk command.
awk 'BEGIN {for ( i=1;i<ARGC;i++ )print "ARGV " i ": [" ARGV[i] "]" }
FNR==1 {print "FILENAME " ++a ": [" FILENAME "]" }
' $( ls )
work fine for standard file name like file1.txt
but problem arise with spaced file name lile file with space
(in fact certainly when file name contains $IFS character and IFS is not to be touch). FILENAME is OK, ARGV separate on space (quoted or not) like if parsed all parameter as one string after shell pass it.
I use this to count file lines even if file is empty (so never reach the FNR == 1 ) but it's not the question here.
So
- how should i format spaced character (i try to surround via sed with quote like
$( ls | sed "s/'/'\"'\"'/g;s/.*/'&'/")
but did'nt help) - how to catch spaced value via ARGV
I use awk on linux and AIX (and not gawk in this case :-( )
some sample
#ls -1 file*
file
file and space
file'qu .txt
file"qu .txt
# awk '...' "file and space"
ARGV 1: [file and space]
FILENAME 1: [file and space]
# awk '...' $( ls file* | sed -e 's/ /?/g' )
ARGV 1: [file]
ARGV 2: [file and space]
ARGV 3: [file'qu .txt]
ARGV 4: [file"qu .txt]
FILENAME 1: [file]
FILENAME 2: [file and space]
FILENAME 3: [file'qu .txt]
last ls show that awk COULD make the difference ( file"qu .txt is an empty file so is FNR==1 never reach).
I see now that this is at shell passing info level, not awk.