Linux通过索引替换命令 [英] Linux replacement command by index

查看:124
本文介绍了Linux通过索引替换命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

卡住。非常困难。

为什么?因为我无法通过给出索引来找出替代命令



我现在正在做的是:

 rploldstringnewstringfilename



ofcourse这会改变所有搜索结果。



我需要的是这样的:

 rplindexnewstringfilename





 rplindexoldstringnewstringfilename





我发现但对我不起作用的是:

 sed'35s /.*/ foo /'$ filename 



其中35是行号

和foo是我要用

^ - 有效,但我似乎无法弄清楚如何建立自己的字符串,

我试过:

 sed'$ {index} s /.*/$ {replacementline}'$ filename 





注意:这条线我是尝试更改文件几次。 (我正在尝试使用索引来解决这个问题,这导致了当前的问题)

我现在已经做了很长时间了......而且我是linux的命令的新手,我自己还没有完成复杂命令的经验。



感谢您帮助^^!

解决方案

filename



其中35是行号

和foo是我要替换旧行的字符串

^ - 工作但我不能似乎弄清楚如何建立我自己的字符串,

我试过:

 sed'


{索引}Š/.*/

{replacementline}

stuck. very stuck.
why? because i can't figure out a replacement command that works by giving an index

what i'm doing now is:

rpl "oldstring" "newstring" "filename"


ofcourse this changes all the search results.

what i need is something like this:

rpl "index" "newstring" "filename"


or

rpl "index" "oldstring" "newstring" "filename"



what i've found but doesn't work for me is:

sed '35s/.*/foo/' $filename


where 35 is the line number
and foo is the string that i want to replace the old line with
^-- works but i can't seem to figure out how to build my own string,
i've tried :

sed '${index}s/.*/${replacementline}' $filename



note: the line i'm trying to change in the file occurs several times. (i'm trying to work with an index to fix this problem, wich caused the current problem)
i've been working on this long enough now.. and i'm new to linux's commands, i haven't got the experience yet to make complex commands myself.

thanks for helping ^^!

解决方案

filename


where 35 is the line number
and foo is the string that i want to replace the old line with
^-- works but i can't seem to figure out how to build my own string,
i've tried :

sed '


{index}s/.*/


{replacementline}'


这篇关于Linux通过索引替换命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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