#List of ids - one per line in allIds.txt $ awk 'BEGIN{while((getline<"allIds.txt")>0)l[">"$1]=1}/^>/{f=!l[$1]}f' seq.fa # You can play with this f=!l[$1 ] if wanted to extract or not extract the ids