如何在文件中使用 sed 命令刪除模式?
我有一個文件,我想刪除所有模式,以便我只保留一些資訊,即該文件的製作者/創建者。
我設法用一個單詞“PATTERN”替換了模式,以便輕鬆刪除它們。我怎樣才能刪除這個詞?以下是我使用的命令:
$ cat /path | tr \n \f | \ tr -cd "[A-Za-z0-9 () /\f] | \ sed s/stream.*endstream/STREAM/ | sed s/[0-9][0-9]* /PATTERN/g | \ sed "s/PATTERN PATTERN n/PTR/g"
我得到這個
/rdfRDF/xxmpmetaxpacket efdwefdstreamefdobjPATTERN PATTERN obj/DisplayDocTitle trueefdobjPATTERN PATTERN obj/Type/XRef/Size PATTERN/W
$$ PATTERN PATTERN PATTERN $$/Root PATTERN PATTERN R/Iffo PATTERN PATTERN R/ID$$ PATTERNFEFPATTERNCPATTERNEPATTERNDBPATTERNFPATTERNEPATTERNFPATTERNEEPATTERNFEFPATTERNCPATTERNEPATTERNDBPATTERNFPATTERNEPATTERNFPATTERNEEPATTERN $$ /Filter/FlateDecode/Lefgth PATTERNstreamxc Z)PATTERNBSekgPBB(FUfLqSuefdstreamefdobjxrefPATTERN PATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN fPATTERN PATTERN frailer/Size PATTERN/Root PATTERN PATTERN R/Iffo PATTERN PATTERN R/ID$$ PATTERNFEFPATTERNCPATTERNEPATTERNDBPATTERNFPATTERNEPATTERNFPATTERNEEPATTERNFEFPATTERNCPATTERNEPATTERNDBPATTERNFPATTERNEPATTERNFPATTERNEEPATTERN $$ startxrefPATTERNEOFxrefPATTERN PATTERNtrailer/Size PATTERN/Root PATTERN PATTERN R/Iffo PATTERN PATTERN R/ID$$ PATTERNFEFPATTERNCPATTERNEPATTERNDBPATTERNFPATTERNEPATTERNFPATTERNEEPATTERNFEFPATTERNCPATTERNEPATTERNDBPATTERNFPATTERNEPATTERNFPATTERNEEPATTERN $$ /Prev PATTERN/XRefStm PATTERNstartxrefPATTERNEOF
如何去掉PATTERN這個詞?
嘗試以下操作:
sed -i -e 's/PATTERN//g' filename