on-internet
← Community

Delete a section of a file Bash Script

Stack Overflow ·

I’m trying to remove 3 lines of code in a file so I thought at first to use sed and rm lines 1-3 like this: sed ‘1d;2d;3d’ file but then my lead system admin said I may run into issues because in another scenario there might be more code so that wouldn’t work. So then I thought maybe to match the lines like this: sed ‘/specific thingy/d’ file-path sed ‘/next thingy/d’ file-path sed ‘/last line/d’ file-path But then he said “what if the lines are different” and it dosent exactly match so then he gave me a hint to use grep. In the actual code the first and third line are comments so how would yo

Comments

Sign in or sign up to comment and upvote.

No comments yet.