【发布时间】:2020-06-11 11:40:56
【问题描述】:
我正在尝试使用 sed 将文本插入文件的第 100 行,我在其他论坛上找到的语法是:
sed -i '' "100i\ text to insert" filename
当我使用它时,我可以在特定行上添加文本,但它会影响已经存在的其他文本并放错位置。
我想在添加到文件的文本之前和之后添加一个新行。
我试过这个sed -i '' "100i\ text to insert other text to insert" filename,但它并没有像例外那样工作。
这是我运行上述命令时的输出。顺序应为<key>,低于该顺序应为<string> 标签。
<key>NSBluetoothAlwaysUsageDescription</key> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This will allow "App" to find and connect to Bluetooth accessories. This app may also use bluetooth to know when you are nearby.</string> <string>This app requires constant access to your location in order to track your position, even when the screen is off or the app is in the background.</string>
我似乎不知道应该在命令中添加什么来添加新行。
我不想打乱我只想在第 100 行插入文本的顺序,如果已经有文本,那么该文本应该换行。
我使用的是 OSX,这就是为什么我有一个空的 ' ' 作为我的扩展名。
谢谢!
【问题讨论】:
-
I am able to add text on a particular line but it affects other text which is already there and misplace it.您能否在您的问题中添加输入和预期输出示例,然后让我们知道? -
只需按 ENTER 即可引入换行符
-
@RavinderSingh13 我更新了问题。你能看看吗
-
@WiktorStribiżew 你的建议没有用。