sd icon indicating copy to clipboard operation
sd copied to clipboard

Can you remove a line with sd?

Open EmilSodergren opened this issue 3 years ago • 2 comments

Is it possible to remove lines with sd? You could of course "replace line with empty" but that leaves unwanted empty blank lines. With sed you write sed -i '/pattern to match/d' ./infile. Is there something similar in sd? I think that functionality is the only thing that still keeps sed in my toolbox... :smile:

EmilSodergren avatar Jun 29 '21 20:06 EmilSodergren

Just use \n in your pattern?

sd 'foo\n' ''

jorunfa avatar Jun 30 '21 11:06 jorunfa

possible dupe of https://github.com/chmln/sd/issues/99

balupton avatar Dec 02 '21 06:12 balupton

As @jorunfa mentioned you just need to include the newline in the pattern. If you want to support text that uses \r\n as well then you can use \r?\n

CosmicHorrorDev avatar Oct 22 '23 00:10 CosmicHorrorDev