如何删除前N个双引号,然后删除最后N个双引号

时间:2019-06-28 19:05:30

标签: bash awk sed

我正在尝试删除前10个引号,然后再删除最后4个引号。

例如:

"one","two","three","four","ten","eleven","thirteen","fourteen"
"one","two","three","four","ten","eleven","thirteen","fourteen"
"one","two","three","four","ten","eleven","thirteen","fourteen"

应变成:

one,two,three,four,five,"eleven",thirteen,fourteen
one,two,three,four,five,"eleven",thirteen,fourteen
one,two,three,four,five,"eleven",thirteen,fourteen

我想重复此sed过程,直到文件结尾(csv)并将其应用于每一行。 一件事是,在一个元素中有换行符,双引号,逗号字符,并留下了引号。我相信这不会改变计数过程,但我担心它可能会与sed混淆,因为它会在看到第一个换行符后停止大小写,并在下一个换行符大小写之后继续,即使它可能位于同一元素中。这是一个例子

"eleven,"quotationmarks"
newline endofeleven"

在这种情况下,应该将整个内容算作1个元素, 这样的过程就像

看着行->删除前10个标记->如果换行符不在其中,则忽略换行符->删除最后4个标记->在每一行重复

我相信sed / awk可以做到这一点,它不必是一个班轮,并且可以有多行代码来实现这一目标。

正在寻找类似https://unix.stackexchange.com/questions/155805/sed-replace-first-k-instances-of-a-word-in-the-file

的内容

0 个答案:

没有答案