sed-devel
[Top][All Lists]
Advanced

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

Distinct BSD sed and GNU sed outputs


From: limited time
Subject: Distinct BSD sed and GNU sed outputs
Date: Wed, 30 Oct 2024 22:21:16 +0530

Hey all, I came across this command which give different outputs for BSD sed 
and gsed :

=============================================

# Simple string for demonstration
❯ for i in 1 2 3 4 5 ; do print -N + ; done                    
+++++%

# Works as expected
❯ for i in 1 2 3 4 5 ; do print -N + ; done | sed -e 's/^/_/g'
_+++++%

# This seems strange :
❯ for i in 1 2 3 4 5 ; do print -N + ; done | sed -e 's/$/_/g'
+_%

# Now using gsed

❯ for i in 1 2 3 4 5 ; do print -N + ; done | gsed -e 's/^/_/g'
_+++++%

# As expected :

❯ for i in 1 2 3 4 5 ; do print -N + ; done | gsed -e 's/$/_/g'
+++++_%


=============================================

Here’s the hexdump of the string for reference, print -N prints arguments 
separated and terminated by nulls :
❯ for i in 1 2 3 4 5 ; do print -N + ; done | hexdump
0000000 002b 002b 002b 002b 002b               
000000a

00 are the nulls and 2b is the + character, 5 of each totalling 10 (a).

I mentioned this to BSD sed's author and this is what he had to say about this 
: 
———————————
The POSIX standard [1] clearly specifies that lines shall be terminated by a 
newline, and doesn't specific a behavior for null input.  So gsed's behavior 
appears to be an extension.

[1] https://pubs.opengroup.org/onlinepubs/9799919799/
———————————

So I just want to confirm if there is any such gsed extension and whether it’s 
documented anywhere.
Thanks.



reply via email to

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