How to replace a search text from a given line num

2019-09-02 12:21发布

问题:

A file mytext.txt has in line number 20

<mytext=SO svn=myrepo number=2.1.0>   

using SED or AWK I would like to change the line number 20 of mytext.txt to

<mytext=SO svn=myrepo number=2.1.6>

回答1:

awk 'NR==20{$0="NEW TEXT"}7' file

next time do some man sed/awk before post.



回答2:

with sed:

sed -ri '20 s/2.1.0/2.1.6/g' file


标签: shell