🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.privacy.anon-server
Article #305782

Using 'sed' to delete a line from a file (Was: Linux Command-Line Editors Vulnerable to High-Severity Bug)

#305782
From: Kenny McCormack
Date: Thu, 20 Jun 2019 12:32
35 lines
2260 bytes
In article <pgtmge5haptnvn6tu35fapmssdrnge92bo@4ax.com>,
chrisv  <chrisv@nospam.invalid> wrote:
...
>>until openssh started printing instructions on how to purge bad
>>records from known_hosts ed was my go-to solution
>>
>>ed ~/.ssh/known_hosts
>>314
>>d
>>w
>>q
>>
>>314 here is line number of the bad record taken from the error message.
>
>vi could have done the same...

Or sed.  Note: I don't often recommend sed - for reasons well explained by
a certain poster in comp.lang.awk, but this is one simple case where using
sed makes sense.

    sed -i.old 314d ~/.ssh/known_hosts

Note that this problem gets more tricky if you want to support deleting
more than one line in a single invocation.  I actually figured out a way to
do this with sed - by invoking sed twice - but I think if I had to do it
over again, I'd do it in gawk instead.

    # Untested, but looks right to me...
    gawk -i inplace 'BEGIN { for (i in ARGV) ToDelete[ARGV[i]] } !(NR in ToDelete)' \
	~/.ssh/known_hosts 314 319 762

-- 
A racist, a Nazi, and a Klansman walk into a bar...

Bartender says, "What will it be, Mr. Trump?"
Technical Details
Message-ID: <qefucv$eri$1@news.xmission.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
References: <qe8q2c$9f8$1@news.mixmin.net> <5vqhge9nua902qvknjh7ocfjg2g6qbv0qi@4ax.com> <qef78p$762$2@gonzo.revmaps.no-ip.org> <pgtmge5haptnvn6tu35fapmssdrnge92bo@4ax.com>

Show Full Headers
Complete Article Headers
Message-ID: <qefucv$eri$1@news.xmission.com>
Subject: Using 'sed' to delete a line from a file (Was: Linux Command-Line Editors Vulnerable to High-Severity Bug)
Date: Thu, 20 Jun 2019 12:32:31 +0000
From: gazelle@shell.xmission.com (Kenny McCormack)
References: <qe8q2c$9f8$1@news.mixmin.net> <5vqhge9nua902qvknjh7ocfjg2g6qbv0qi@4ax.com> <qef78p$762$2@gonzo.revmaps.no-ip.org> <pgtmge5haptnvn6tu35fapmssdrnge92bo@4ax.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
Newsgroups: alt.privacy.anon-server,alt.os.linux,comp.os.linux.misc,comp.os.linux.advocacy
Organization: The official candy of the new Millennium
Injection-Date: Thu, 20 Jun 2019 12:32:31 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
Lines: 35