- You can use
cut
to extract just themaleID
from the file; to match the individual 3 (or 27), you can usegrep
. - You want to turn the solution of part 1 into a script; to do so, open a new file and copy the code you've written. Now you can use generic variables
$1
and$2
as placeholders for the file name and themaleID
; you can pass these arguments to the command line. - First, you need to use
cut
in combination withtail
,sort
anduniq
to extract all the distinctmaleID
. Then the main hurdle is to take the output of this pipeline and use it as input for a for loop inbash
. The following example should help:
#!/bin/bash
# to store the results of a command into a variable,
# surround the command with backticks (`)
myfiles=`ls`
for myfile in $myIDS
do
echo $myfile
done