【发布时间】:2022-01-26 15:00:16
【问题描述】:
我正在查找一个文件,该文件中偶尔会出现包含交替空格的单词。
例如:
h e l l o this is an e x a m p l e
我希望它变成:
hello this is an example
我愿意使用任何命令行工具来解决这个问题。我会冒单个字符单词被压扁的风险(因为它们很少出现在我的文件中)。
E. g.:h e l l o this is a r i s k I would take.变成hello this is ariskI would take.
到目前为止,我尝试的是这样,但我想我需要向前看:
sed "s/\([[:alnum:]]\) \([[:alnum:]]\)/\1\2/g" mytextfile.txt
这只会给我:
he ll othisisane xa mp le
我只找到有关如何修剪字符串或删除字符串中所有空格的主题。
【问题讨论】:
-
h e l l o this is an e x a m p le几乎是不可能的,除非你将期望降低到hello this is an examp le -
@MonkeyZeus 感谢您指出这一点,同时约翰为我纠正了这个错字。