sed + 仅在文件的最后一行删除字符串 [英] sed + remove string only in the last line of the file

查看:58
本文介绍了sed + 仅在文件的最后一行删除字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下 sed 命令从文件中删除 line number 字符串

I use the following sed command to remove the line number string from file

sed -i s'/line number//g' file

但是我需要在 sed 语法中更改以删除 行号仅当它存在于文件的最后一行时?

but what I need to change in sed syntax in order to remove the line number only if it exist in the last line of the file?

推荐答案

我不确定我是否完全理解您的问题,但是这可以帮助您:

I'm not sure I fully understand your question, however this can help you :

sed -i '$ s/line number//g' file

这只会在最后一行执行替换(因为$),将行号替换为空.

This will perform substitution only on last line (because of $), replacing line number by nothing.

man sed地址部分可以帮助您了解如何在部分文本上应用 sed 命令.

man sed, section Addresses can help you understand how to apply sed commands on part of the text.

这篇关于sed + 仅在文件的最后一行删除字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆