【问题标题】:Replace punctuation by one space用一个空格替换标点符号
【发布时间】:2013-12-27 16:00:59
【问题描述】:

我用这个命令列出了文本中的所有标点符号

 perl -CSD -nE '$seen{$1}++ while /(\pP)/g; END { say "$_ $seen{$_}" for keys %seen }' file.txt

然后如何用一个空格''替换它

例如

Said Mr. Nkumbula last night: "We want to discuss what to do
if the British Government gives in to Sir Roy and the talks fall
through. There are bound to be demonstrations."

会变成

Said Mr  Nkumbula last night   We want to discuss what to do
if the British Government gives in to Sir Roy and the talks fall
through  There are bound to be demonstrations  

【问题讨论】:

  • “发音”没有意义。你说的是标点符号吗?你能给我们一个小样本输入和预期输出吗?

标签: perl shell unix


【解决方案1】:

  perl -pe 's/\pP/ /g' file.txt

做你期望的?替代方案:列出你不想要的字符:

  sed -e 's/[.":;]/ /g' file.txt

【讨论】:

  • 它完全符合您的要求。由于 \pP 涉及 unicode,因此可能是语言环境问题。查看替代方案。
猜你喜欢
  • 2016-04-23
  • 2021-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-10
  • 1970-01-01
  • 2016-06-07
  • 1970-01-01
相关资源
最近更新 更多