web analytics

Perl: print the name of the input file

The special variable $ARGV could be used to get the name of the input file. It returns the name of the file or ‘-‘ if the standard input was used.

Here are some examples:

perl -nle ‘END { print $ARGV }’ /etc/passwd /etc/passwd echo test | perl -nle ‘print $ARGV’ – $ (echo test; echo […]

grep in find command: how to display file names

Here is very simple trick to force the grep command to display file name, when it’s used together with find operation. Just write /dev/null as the “second file”

find . -type f -exec grep somestring {} /dev/null \;