Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current filename for find/xargs/perl -ne?

I'm working in the shell, trying to find NUL chars in a bunch of CSV files (that Python's CSV importer is whinging about, but that's for another time) using the so-proud-of-my-ever-clever-self:

find ~/path/ -name "*.csv" -print0 | \
xargs -n 1 -0 \
perl -ne 'if(m/\x{00}/){print fileno(ARGV).join(" ",@ARGV).$_;}'

Except I see no filename. Allegedly the implicit <> operator that perl -ne is wrapping my script in is just using @ARGV / the ARGV filehandle, but neither of the above is giving me the name of the current file.

How do I see the current filename (and, ideally, line number) in the above?

like image 380
pauloppenheim Avatar asked Dec 28 '22 21:12

pauloppenheim


1 Answers

$ARGV is the name of the current file and $. is the current line number; see perldoc perlvar and I/O Operators in perldoc perlop. (Note that $. doesn't reset between files; there's discussion of that in perldoc -f eof.)

And I'm not entirely sure what you're trying to accomplish with that print; it will give you the filehandle number, which is probably 3, prepended to a space-separated list of filenames (which should probably be only the one because of xargs -n), then the current line which will include the NUL and other potentially terminal-confusing characters.

like image 74
geekosaur Avatar answered Jan 12 '23 00:01

geekosaur