List files containing PATTERN in first line of a file:
perl -ne'print "$ARGV\n" if /PATTERN/; close ARGV' *.txt
List files not containing PATTERN in first line of a file:
perl -ne'print "$ARGV\n" unless /PATTERN/; close ARGV' *.txt
| #!/bin/bash | |
| # move.sh - move files with specified pattern in first line to target dir. | |
| USAGE="Usage: $0 PATTERN FILES... DIR" | |
| if [ "$#" == "0" ]; then | |
| echo "$USAGE" | |
| exit 1 | |
| fi | |
| PATTERN=$1 | |
| TARGET_DIR=${!#} | |
| shift | |
| for i in "$@" | |
| do | |
| if [ -f $i ] && [ `perl -ne'print 1 if /'$PATTERN'/; close ARGV' $i` ] | |
| then | |
| echo "Moving $i to $TARGET_DIR" | |
| mv $i $TARGET_DIR | |
| fi | |
| done |