如果我有一个文件
half a pound
of tuppenny rice
half a pound
that's the way
the money goes
pop goes the weasel
我想在第 4 行插入一行“of treacle”。因此应该是
half a pound
of tuppenny rice
half a pound
of treacle
that's the way
the money goes
pop goes the weasel
我如何在 Windows 的 sed 中执行此操作。我正在使用 gnuwin32 的 sed。
答案1
C:\Users\username>type afile.txt
half a pound
of tuppenny rice
half a pound
that's the way
the money goes
pop goes the weasel
C:\Users\username>
C:\>sed "4i\of treacle" afile.txt
half a pound
of tuppenny rice
half a pound
of treacle
that's the way
the money goes
pop goes the weasel
C:\>
您可以使用sed "3a\of treacle" afile.txt
i 插入到该行之前。4i 将位于第 4 行之前。a 插入到该行之后。3a 将位于第 3 行之后。因此,3a 与 4i 相同。