bug-sed
[Top][All Lists]
Advanced

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

bug#24615: [PATCH] sed: handle the patterns which consist of ^ or $ manu


From: Norihiro Tanaka
Subject: bug#24615: [PATCH] sed: handle the patterns which consist of ^ or $ manually
Date: Wed, 05 Oct 2016 00:18:58 +0900

The patterns which consist of only ^ or $ often appear in substitution.
For example, If we change a CSV file into double quoted, will do as
following.

  sed 's/^/"/; s/$/"/; s/,/","/g' in >out

First and second substitutions are "the patterns which consist of only ^
or $".

However, regex are not good at them, as regex does not build fastmap for
them, and as all in buffer must be scanned for $.  So the patch changes
them into handling manually.

$ yes 12345,67890,12345,67890,12345,67890,12345,67890  | head -1000000 >in

$ time -p env LC_ALL=C sed/sed 's/^/"/; s/$/"/; s/,/","/g' in >/dev/null
real 3.48
user 3.47
sys 0.01

This case was improved by the patch as following.

$ time -p env LC_ALL=C sed/sed 's/^/"/; s/$/"/; s/,/","/g' in >/dev/null
real 1.43
user 1.40
sys 0.02

Attachment: 0001-sed-handle-the-patterns-which-consist-of-or-manually.patch
Description: Text document


reply via email to

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