$ cat xxxx adasasd AZII* dasdasd eregrg rtghyth ujyyujyu ghnggh AZII* rtrthyyt juhgj AZII* fddfgd hgftyhyj iukuikuik AZII* gytty ioiukuy $ perl -ne 'print if /^AZII\*/ ... /^AZII\*/;' xxxx > yyyy $ cat yyyy AZII* dasdasd eregrg rtghyth ujyyujyu ghnggh AZII* AZII* fddfgd hgftyhyj iukuikuik AZII* $