How to search and replace the specific line number string

后端 未结 2 839
一向
一向 2021-01-27 02:52
line_index=\"2d\";

file=\"./Desktop/books.sh\";

sed -i.bak -e $line_index $file

Will delete the entire line that $line_index is pointing to



        
相关标签:
2条回答
  • 2021-01-27 03:13

    To restrict substitution to a line number, add it before the command:

    sed -i "2s/harry/potter/" $file
    
    0 讨论(0)
  • 2021-01-27 03:32

    Sure, "addresses" and "commands" can be freely combined:

    sed '2s/harry/potter/g'
    
    0 讨论(0)
提交回复
热议问题