[Surfraw-devel] Patch: use awk instead of sed for listing elvi
Keith Smiley
keithbsmiley at gmail.com
Mon Sep 14 04:34:41 UTC 2015
Thanks, this works as expected on OS X.
--
Keith Smiley
On 09/13, Kyle Isom wrote:
> Hello,
>
> In response to Keith's earlier email, I swapped out awk for sed in
> the list_elvi function in surfraw. The awk syntax for doing this is
> more portable across different implementations of awk than the
> equivalent sed expression.
>
> Tested on OS X 10.10.5:
> $ awk --version
> GNU Awk 4.1.3, API: 1.1
> ...
> $ mawk -W version
> mawk 1.3.4 20141027
>
> Test on Debian GNU/Linux 8.2 (jessie):
> $ gawk --version
> GNU Awk 4.1.1, API: 1.1 (GNU MPFR 3.1.2-p3, GNU MP 6.0.0)
> $ mawk -W version
> mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan
> $ original-awk --version
> awk version 20121220
>
> Test on OpenBSD 5.7 GENERIC.MP#3 i386:
> $ awk -V
> awk version 20110810
> ---
> surfraw.IN | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/surfraw.IN b/surfraw.IN
> index 0de3c96..8471216 100755
> --- a/surfraw.IN
> +++ b/surfraw.IN
> @@ -323,9 +323,9 @@ w3_parse_option_hook () {
> }
>
> list_elvi() {
> - local dir="$1"
> - sed -n 's/^.*elvis:[ ]\+\(.*\)$/\1/p' $(find "$dir" ! -type d ! -type l ! -name '*~' | sort)
> - for script in $(find "$dir" ! -type d -type l | sort) ; do
> + local_dir="$1"
> + awk '/^#[ ]+elvis:[ ]+/{ sub("^# elvis: ",""); print $0; }' $(find "$local_dir/" ! -type d ! -type l ! -name '*~' | sort | xargs)
> + for script in $(find "$local_dir/" ! -type d -type l | sort) ; do
> printf '%-16s--> %s\n' $(basename "$script") $(basename $(readlink "${script}"))
> done
> }
>
>
> Cheers,
> Kyle
More information about the Surfraw-devel
mailing list