简体   繁体   English

无法从Bash中的txt文件中删除单引号或双引号

[英]Unable to remove single or double quotes from txt file in Bash

I'm trying to remove all punctuation from a text file, and decided to try to use this code: 我正在尝试从文本文件中删除所有标点符号,并决定尝试使用以下代码:

$ cat file | tr -d [:punct:] 

I also attempted with some added single quotes: 我还尝试添加一些单引号:

$ cat file | tr -d'[:punct:]'

and double bracketed 和双括号

$ cat file | tr -d[[:punct:]]

While most of the punctuation is deleted from the text, the single and double quotes remain. 从文本中删除了大多数标点符号后,单引号和双引号仍然保留。 I tried just deleting the quotes with code like this: 我试着只是用这样的代码删除引号:

$ tr -d \'\" file

but this also fails to remove the punctuation and takes out some random letters instead. 但这也无法删除标点符号,而是取了一些随机字母。
I would love to know how to resolve this error and ideally find a way to remove all the punctuation, including quotes, in one line. 我很想知道如何解决此错误,并且理想地找到一种在一行中删除所有标点符号(包括引号)的方法。 Thank you! 谢谢!

I suggest: 我建议:

tr -d '[:punct:]' < file

Example: 例:

echo 'Abc.!?#,"`'"'" | tr -d '[:punct:]'

Output: 输出:

Abc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM