for f in *.txt; do head -10 $f > /directory/$f; done
grep -n -b -m 1 -w ".*im_looking.*" /directory/*.txt > oufile.out
The first line is a for ; do ; done
The f in *.txt
creates a list of filenames ending with .txt in the current directory and each filename is assigned in turn to the variable f on each pass through the loop. The head -10 $f
reads the first ten lines in the file with the filename in the variable f. The > /directory/$f
sends (redirects) the lines that were read to a file with the same name in another directory. You need to supply an appropriate directory name.
The second line searches for whole words containing the string im_looking
in the newly created files. The > oufile.out
sends (redirects) the results of the search to the file outfile.out in the current directory.