bug-sed
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#35195: sed '/^$/d' does not delete empty lines


From: Assaf Gordon
Subject: bug#35195: sed '/^$/d' does not delete empty lines
Date: Mon, 8 Apr 2019 16:07:53 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

tags 35195 notabug
close 35195
stop

Hello,

On 2019-04-08 6:02 a.m., Chin Huat Tan wrote:
sed '/^$/d' does not delete empty lines on the attached file.

The attached file contains windows-style line-ends (\r\n , aka carriage-return + line feed):

   $ head -n 3 LLK-01.txt | od -c -An
    h   t   t   p   s   :   /   /   w   w   w   .   y   o   u   t
    u   b   e   .   c   o   m   /   w   a   t   c   h   ?   v   =
    t   w   x   q   l   U   K   d   Y   q   g  \r  \n  \r  \n   h
    t   t   p   s   :   /   /   w   w   w   .   y   o   u   t   u
    b   e   .   c   o   m   /   w   a   t   c   h   ?   v   =   L
    e   I   h   O   u   T   N   v   M   8  \r  \n

Therefor lines are not really empty (from unix POV),
as they contain a '\r' character.

You can use "dos2unix" utility to convert the file to unix-style.
    dos2unix LLK-01.txt
    sed '/^$/d' LLK-01.txt

You can use 'tr' to delete the '\r' characters:
    cat LLK-01.txt | tr -d '\r' | sed '/^$/d'

Or you can instruct sed to accept these characters as well:
    sed '/^\r*$/d' LLK-01.txt


As such I'm closing this as "not a bug", but discussion can continue by
replying to this thread.

regards,
 - assaf






reply via email to

[Prev in Thread] Current Thread [Next in Thread]