gpt4 book ai didi

linux - 如何使用awk将csv文件中的 ""“fasdfe """更改为 "fasdfe"?

转载 作者:太空宇宙 更新时间:2023-11-04 05:40:21 26 4
gpt4 key购买 nike

我的 file.csv 有 2 列,现在看起来像这样:

"""lkBBW4/9BbP/xKxPodjUPA""",7.767066345448011e-05
"""ogiEVE6t+YVtvR1y/56nKA""",5.406898520316803e-05
"""FxfYC7JayTJ+pYdr2qhHsw""",8.7088198609513e-05
...

有什么办法可以将其转换为:

"lkBBW4/9BbP/xKxPodjUPA",7.767066345448011e-05
"ogiEVE6t+YVtvR1y/56nKA",5.406898520316803e-05
"FxfYC7JayTJ+pYdr2qhHsw",8.7088198609513e-05
...

在ubuntu中使用awk?

更新的问题:如何更改

"lkBBW4/9BbP/xKxPodjUPA",7.767066345448011e-05
"ogiEVE6t+YVtvR1y/56nKA",5.406898520316803e-05
"FxfYC7JayTJ+pYdr2qhHsw",8.7088198609513e-05
...

lkBBW4/9BbP/xKxPodjUPA,7.767066345448011e-05
ogiEVE6t+YVtvR1y/56nKA,5.406898520316803e-05
FxfYC7JayTJ+pYdr2qhHsw,8.7088198609513e-05
...

最佳答案

通过awk,

$ awk -v FS='"""' '{print "\""$2"\""$3}' file
"lkBBW4/9BbP/xKxPodjUPA",7.767066345448011e-05
"ogiEVE6t+YVtvR1y/56nKA",5.406898520316803e-05
"FxfYC7JayTJ+pYdr2qhHsw",8.7088198609513e-05

您可以简单地通过 sed 来完成此操作,

$ sed 's/"\+/"/g' file
"lkBBW4/9BbP/xKxPodjUPA",7.767066345448011e-05
"ogiEVE6t+YVtvR1y/56nKA",5.406898520316803e-05
"FxfYC7JayTJ+pYdr2qhHsw",8.7088198609513e-05

更新问题的答案:

$ awk -v FS='"' '{print $2$3}' file
lkBBW4/9BbP/xKxPodjUPA,7.767066345448011e-05
ogiEVE6t+YVtvR1y/56nKA,5.406898520316803e-05
FxfYC7JayTJ+pYdr2qhHsw,8.7088198609513e-05

或者

$ awk '{gsub(/"/,"")}1' file
lkBBW4/9BbP/xKxPodjUPA,7.767066345448011e-05
ogiEVE6t+YVtvR1y/56nKA,5.406898520316803e-05
FxfYC7JayTJ+pYdr2qhHsw,8.7088198609513e-05

如果您想在单个命令中执行上述步骤,请尝试以下 awk 代码。(即删除所有 """)

$ cat file
"""lkBBW4/9BbP/xKxPodjUPA""",7.767066345448011e-05
"""ogiEVE6t+YVtvR1y/56nKA""",5.406898520316803e-05
"""FxfYC7JayTJ+pYdr2qhHsw""",8.7088198609513e-05
<小时/>
$ awk '{gsub(/"""/,"")}1' file
lkBBW4/9BbP/xKxPodjUPA,7.767066345448011e-05
ogiEVE6t+YVtvR1y/56nKA,5.406898520316803e-05
FxfYC7JayTJ+pYdr2qhHsw,8.7088198609513e-05

关于linux - 如何使用awk将csv文件中的 ""“fasdfe """更改为 "fasdfe"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25616592/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com