svn commit: r278467 - head/usr.sbin/bsdconfig/share

Devin Teske dteske at FreeBSD.org
Mon Feb 9 19:52:15 UTC 2015


sed was an odd-man out.

awk is used almost 200 times, and sed only once.

Consider it the removal of an unnecessary dependency.

If there were similar cases of a utility only being used once,
I would probably do the same thing (e.g., if “tr” was used only
once, I might convert it to “awk”).

I’m very big on minimizing dependencies because I use this
stuff in embedded situations.

Yeah, the sed binary is smaller… but it just didn’t make much
sense to me to use sed only once when awk would do just fine
(considering awk is a hard-and-fast dependency with almost
200+ occurrences).
— 
Devin

P.S. Sorry for top-posting.


> On Feb 9, 2015, at 11:24 AM, Baptiste Daroussin <bapt at FreeBSD.org> wrote:
> 
> On Mon, Feb 09, 2015 at 07:16:19PM +0000, Devin Teske wrote:
>> Author: dteske
>> Date: Mon Feb  9 19:16:19 2015
>> New Revision: 278467
>> URL: https://svnweb.freebsd.org/changeset/base/278467
>> 
>> Log:
>>  Replace the only instance of sed(1) in bsdconfig(8) with awk(1).
>> 
>>  MFC after:	3 days
>> 
>> Modified:
>>  head/usr.sbin/bsdconfig/share/keymap.subr
>> 
>> Modified: head/usr.sbin/bsdconfig/share/keymap.subr
>> ==============================================================================
>> --- head/usr.sbin/bsdconfig/share/keymap.subr	Mon Feb  9 17:53:16 2015	(r278466)
>> +++ head/usr.sbin/bsdconfig/share/keymap.subr	Mon Feb  9 19:16:19 2015	(r278467)
>> @@ -219,7 +219,7 @@ f_keymap_get_all()
>> 			echo -n "$k "
>> 			# NOTE: Translate '8x8' to '8x08' before sending to
>> 			# sort(1) so that things work out as we might expect.
>> -			debug= keymap_$k get desc | sed -e 's/8x8/8x08/g'
>> +			debug= keymap_$k get desc | awk 'gsub(/8x8/,"8x08")||1'
>> 		done | sort -k2 | awk '{
>> 			printf "%s%s", (started ? " " : ""), $1; started = 1
>> 		}'
> 
> Out of curiosity what is the point of preferring awk over sed? the awk binary
> being larger and depending on 2 libraries versus sed only depending on one?
> 
> Best regards,
> Bapt



More information about the svn-src-head mailing list