删除行情awk或sed

时间:2014-07-16 19:22:24

标签: string bash awk sed quotes

我有一个CSV文件,除非在字符串中,否则只想删除所有引号。

示例:

"I have a file that says "need help" please"

除非在双引号内,否则我想删除文本中的所有双引号。例如,不要删除“需要帮助”周围的引号

任何人都有线索?

我在awksed命令方面做得非常好,但这个让我很难过。

感谢您的帮助!

2 个答案:

答案 0 :(得分:2)

根据您的CSV格式和要求,这可能会也可能不会达到您想要的效果:

$ cat file
"I have a file that says "need help" please"
"a "b" c","d "e" f"
$
$ awk -F'","' -v OFS=, '{$1=$1;gsub(/^"|"$/,"")}1' file
I have a file that says "need help" please
a "b" c,d "e" f

答案 1 :(得分:0)

使用grep -Po '".*?"'

echo 'this is a test "I need help" and "it has to be now"' | grep -Po '".*?"'
"I need help"
"it has to be now"