문제

I would like to change a specific line in a text file.

I have tried with this

perl -p -i  -e "s/JAI/ramkrishna/ if $. == 37" test.tex

But it is just deleting JAI but not writing ramkrishna.

도움이 되었습니까?

해결책

Your command works just fine. I guess you have the line number wrong?

With a test.tex file like this

aa
bb
cc
aa bb cc JAI dd ee ff
bb
cc
aa bb cc JAI dd ee ff
xx
yy
zz

the command

perl -p -i  -e 's/JAI/ramkrishna/ if $. == 7' test.tex

changes the file to

aa
bb
cc
aa bb cc JAI dd ee ff
bb
cc
aa bb cc ramkrishna dd ee ff
xx
yy
zz

다른 팁

sed '37s/JAI/ramkrishna/' filename
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top