#!/bin/bash resultDir=output/random/*dat filteredDir=output/random/filtered/ for file in $resultDir; do echo "Processing file $file" cat $file | grep conductance | sed 's/Cluster conductance: //g' | grep -v NaN > $filteredDir`basename $file` done