简体   繁体   中英

How can i use sed -i command to replace the occurance of character starting from particular line in a file till another line?

I have a text file in which I want to replace the occurrence of "#" with blank character starting from say line 10th to 20th for example My file is as follows:

some text here
some text here
some text here
#here1
#here2
#here3
#here4
#here5
erverv
ererver

so here from line 4 to 8 i want to remove character #. How can I achieve that using sed -i command?

使用地址范围:

sed -i -e '10,20s/^#//' file

you can use

sed 's/#//' -i yourfile

With the -i flag it edits yourfile in place and removes all # You probalby want this to only remove # at the beginning of your file

sed 's/^#//' -i yourfile

However only doing this for certain lines and not all I would recommend awk . See man awk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM