如何从文件中删除特定数字?

如何从文件中删除特定数字?

我有一个文本文件,其中包含以下内容

DESCRIPTION  ENABLED
 Tracker_EG32747257_0418_0618, {NAME => d, DATA_BLOCK_ENCODING => NONE, BLOOMFILTER => ROW, REPLICATION_SCOPE => 0, COMPRESSION => LZ4, VERSIONS => 100000, MIN_VERSIONS => 0, TTL => 2419200 SECONDS (28 DAYS), KEEP_DELETED_CELLS => false, BLOCKSIZE => 65536, IN_MEMORY => false, BLOCKCACHE => true} true

1 row(s) in 0.0340 seconds

DESCRIPTION  ENABLED
 Tracker_EG38863805_0418_0618, {NAME => d, DATA_BLOCK_ENCODING => NONE, BLOOMFILTER => ROW, REPLICATION_SCOPE => 0, COMPRESSION => LZ4, VERSIONS => 100000, MIN_VERSIONS => 0, TTL => 2419200 SECONDS (28 DAYS), KEEP_DELETED_CELLS => false, BLOCKSIZE => 65536, IN_MEMORY => false, BLOCKCACHE => true} true

1 row(s) in 0.0300 seconds

DESCRIPTION  ENABLED
 Session_EG32747257_0418_0618, {NAME => d, DATA_BLOCK_ENCODING => NONE, BLOOMFILTER => ROW, REPLICATION_SCOPE => 0, COMPRESSION => LZ4, VERSIONS => 1, MIN_VERSIONS => 0, TTL => 2419200 SECONDS (28 DAYS), KEEP_DELETED_CELLS => false, BLOCKSIZE => 65536, IN_MEMORY => false, BLOCKCACHE => true} true

1 row(s) in 0.0270 seconds

DESCRIPTION  ENABLED
 Session_EG38863805_0418_0618, {NAME => d, DATA_BLOCK_ENCODING => NONE, BLOOMFILTER => ROW, REPLICATION_SCOPE => 0, COMPRESSION => LZ4, VERSIONS => 1, MIN_VERSIONS => 0, TTL => 2419200 SECONDS (28 DAYS), KEEP_DELETED_CELLS => false, BLOCKSIZE => 65536, IN_MEMORY => false, BLOCKCACHE => true} true

1 row(s) in 0.0260 seconds....

现在我想删除所有“DESCRIPTION”单词和所有 1(不是任何包含 1 的单词)

我正在使用这个命令,

sed 's/\(DESCRIPTION\|<1>\)//g'

它会删除所有描述字,还会删除文件中的所有 1 数字。

答案1

您似乎正在使用 GNU sed(POSIXsed未定义\|)。然后你也可以使用 perlish 单词边界,但是你需要转义它们以使其变得<>特殊:

sed 's/\(DESCRIPTION\|\<1\>\)//g'

答案2

尝试:

sed 's/^\(\<DESCRIPTION\>\|\<1\>\)//' infile

因为您使用了global 选项,并且它确实删除了所有出现的 1 ,并且它DESCRIPTION也会这样做。如上所述,^仅当行以这些开头时,您才需要行首锚点来删除 1 和说明。

相关内容