From owner-freebsd-questions@freebsd.org Tue Nov 7 18:54:06 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A7964E61DE9 for ; Tue, 7 Nov 2017 18:54:06 +0000 (UTC) (envelope-from jd1008@gmail.com) Received: from mail-io0-x232.google.com (mail-io0-x232.google.com [IPv6:2607:f8b0:4001:c06::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 676A7805B0 for ; Tue, 7 Nov 2017 18:54:06 +0000 (UTC) (envelope-from jd1008@gmail.com) Received: by mail-io0-x232.google.com with SMTP id m16so3249065iod.1 for ; Tue, 07 Nov 2017 10:54:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-transfer-encoding; bh=3Sm8WbQREKI4tDnCUAhc4988N2QA12D5b2DZPO3Y154=; b=WYiwaXX3CB+IDqCGODBtvq3wZ8R4NmOrb/T/aFzsh3ho9BG7HinPIxhU3RtdoIBubw RGWKbgUlyEY7Ha68ZH8TE6rFIFRi6qH1GRlDX8dcTN+Uwv1NKSpKx3Xo4TCzw+TH7omc WC+/kT/SBU+0TA+zztAnT/VDsBbgIKy5vc8lCvlI3Ilfbv5F6495B1wlnjcP0itbyMx7 FfD1mtRM7l8ZF9k7XQrPw/gRzr791ybLGa9IsmLZfhzE4Y1egUw0cJXh5VfnwxBTJ2Qr mCpvoxO9faBafEzHxBeAeAGUQaTLfgrPI2l6/rEHfH9ixXdohqJEU+N6akxyZtFabw9W qWGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-transfer-encoding; bh=3Sm8WbQREKI4tDnCUAhc4988N2QA12D5b2DZPO3Y154=; b=mXWlOeKjyUQxCFDmP/yHmHBvnRPeEqgSQaptRPcyHxjmGIKZXQ5mDDQA7nq8jMA8dA kHA4o0hPRMgA4n0e/Ywyhuu8EAVkVpGiKYaka7lh43UgDE0ngYD872LhU2mJwNYYBDdF ffK3WzB/rHMCVSgFlxlB9VdA9JaE4GukAtPzrqzUk7WUaj25ChuKzjAMBVG1PEVyz7ka GOTHzRSBCNFuXExkRmK13MSRegseyWsXBPehZUu0D0gbgNcQhyOxsstaceyLdKHLJHpo 8qA9E3nqbLPWu+mFZT88jwbaqNLKdcVWQO1wd0en3mPvT4/eolIW7Juty3heggiaYKbX CYJg== X-Gm-Message-State: AJaThX4egRF7Vqg1AhFdGZHcI42u3dKqLCBVJd78EX/V2VLcraDDtmie HgGFPFg/QMD+EzICoObWAQBCjA== X-Google-Smtp-Source: ABhQp+QE+Plw7fTgWLxatNtGe6JZFmsLZdwWmRJynJIThnUWx2a5KwfQx/rEGesBh3Gp119/ReAUhg== X-Received: by 10.107.112.3 with SMTP id l3mr25827548ioc.105.1510080845645; Tue, 07 Nov 2017 10:54:05 -0800 (PST) Received: from localhost.localdomain (50-243-4-3-static.hfc.comcastbusiness.net. [50.243.4.3]) by smtp.googlemail.com with ESMTPSA id d186sm1098693itd.38.2017.11.07.10.54.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 10:54:05 -0800 (PST) Message-ID: <5A02014B.3050804@gmail.com> Date: Tue, 07 Nov 2017 11:54:03 -0700 From: JD User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: freebsd-questions@freebsd.org Subject: Re: sed - remove nul lines from file References: <88a59a82-2902-9f63-0a94-bd23b910e7ad@gmx.com> <88b1870184a8810072fe503917cd86be.squirrel@webmail.harte-lyne.ca> <656b08b1-b79d-8e7e-27ec-e39d883f2355@gmx.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Nov 2017 18:54:06 -0000 On 11/07/2017 11:46 AM, James B. Byrne via freebsd-questions wrote: > On Tue, November 7, 2017 13:28, Yuri Pankov wrote: >> On Tue, 7 Nov 2017 21:20:40 +0300, Yuri Pankov wrote: >>> On Tue, 7 Nov 2017 13:14:08 -0500, James B Byrne Via >>> Freebsd-questions >>> wrote: >>>> On Tue, November 7, 2017 13:03, Yuri Pankov wrote: >>>> >>>>> You want /d, not /g, to delete the *lines* which contain NUL >>>>> symbols >>>>> (that's what your subject line said). >>>>> >>>> Sigh. Thank you. That works. However, it also deletes any line >>>> that >>>> has even one NUL in it regardless of the presence of other non-nul >>>> characters on the line. >>>> >>>> What I wish to accomplish is to delete only the lines that are >>>> completely nul. I thought that this could be accomplished by >>>> prefacing the match sting with the start of line anchor ^ and >>>> ending >>>> it with the end of line anchor $ but this does not work as I >>>> expect. >>> "[[.NUL.]]" is just a character specified by its collation name, so >>> treat as any other ordinary character: >>> >>> sed -E '/^[[.NUL.]]+$/d' INFILE > OUTFILE >>> >>> Need extended regexp here for '+' to work. >> >> Or, after looking at re_format(7), it could be written using BREs, >> your >> choice :-) >> >> sed '/^[[.NUL.]]\{1,\}$/d' >> > sed '/^[[.NUL.]]\{0,\}$/d' INFILE > OUTFILE > > Which has no effect. OUTFILE and INFILE remain identical. I get the > exact same result from the first invocation as well. Likewise: > > sed '/^[[.NUL.]]\{1,\}$/d' INFILE > OUTFILE > > and > > sed -E '/^[[.NUL.]]+$/d' INFILE > OUTFILE > > # diff INFILE OUTFILE > # > # ll INFILE OUTFILE > -rw-r--r-- 1 root wheel 61480 Nov 7 13:09 INFILE > -rw-r--r-- 1 root wheel 61480 Nov 7 13:38 OUTFILE > > > I had actually tried these combinations, or at least I believe that I > tried these, before I wrote. Given the complexity and arcane nature > of whatever flavour of RE one is working with I may have transgressed > and written them slightly differently. But the examples you provided > me with give the results I obtained exactly. > Did you try tr -d that I posted earlier? tr -d works just fine. To wit: $ cat -v /tmp/x ################################################ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^ $ tr -d '\000' < /tmp/x > /tmp/x2 $ cat -v /tmp/x2 ################################################