| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
When I do the time tests, I get a similar result.
$ time onlysed.sh big.txt 3
real 0m1.787s
user 0m1.684s
sys 0m0.016s
$ time puresed.sh big.txt 3
real 0m0.363s
user 0m0.424s
sys 0m0.008s
Again, from a practical point of view, I think the speed difference
matters little, because in absolute time both are fast. Practically,
readability and maintainability seem much more important (IMO).
However, the speed differences are interesting, as you point out,
because the ranking is different from what one might have guessed based
on the number of sed invocations. In that one sed invocation, it's doing
a lot of stuff, so it makes sense.
Of course the onlysed.sh version would need to skip the first line. It's
easy to fix, and would make the complex syntax only slightly more complex.
It is remarkable "sedonly" is sed-only, and is parameterized.
Unless I am missing something, I would offer one suggestion, to make it
a little easier to read, by simplifying the quoting:
sed -r "
h
s/^([^;]*;){$COL}([^;]*);.*/\2/
s/[A-Z]+/\L\u\0/gi
H
x
s/^(([^;]*;){$COL})[^;]*(;.*)\n(.*)/\1\4\3/
" $1 >fff
Daniel
On 12/12/2015 2:27 PM, Thierry Blanc [sed-users] wrote:
> here the first sed version for this topic, slightly modified.
>
> Even with one single sed invocation, it takes about 5 times longer than
> the puresed.sh
>
> $ wc -l test.csv
> 36634 test.csv
>
> $ time ./puresed.sh test.csv 3
> .361014737
>
> real 0m0.368s
> user 0m0.803s
> sys 0m0.069s
>
> $ time ./only.sed.sh test.csv 3
> 1.526779118
>
> real 0m1.537s
> user 0m1.494s
> sys 0m0.044s
>
> only.sed.sh
> #!/bin/bash
>
> COL=$2
> ((COL--))
>
> sed -r '
> h
> s/^([^,]*,){'"$COL"'}([^,]*),.*/\2/
> s/[A-Z]+/\L\u\0/gi
> H
> x
> s/^(([^,]*,){'"$COL"'})[^,]*(,.*)\n(.*)/\1\4\3/
> ' $1 >fff
>
------------------------------------
------------------------------------
--
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/sed-users/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/