| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
In a way, I agree Rakesh's piece of code shows the art of shell scripts,
is a true gem. It's creative and technically advanced.
However, I would not hold it up as an example of how to write a shell
script, at least a script used for practical purposes, if that was your
meaning. To me, the art of shell scripting (or any programming) is to
make things work correctly and be as clear as possible so another
competent programmer, or myself six months in the future, can quickly
figure out the logic and how to modify or fix the code. "cryptic and
obscure on the first sight even for someone who knows scripting
(geniuses excluded)" means "big maintenance problem". And there seem to
be much clearer alternatives that run just as fast.
I do agree it illustrates advanced features of shell programming, so
advanced at times it boggles the mind. :)
Daniel
On 12/12/2015 2:42 PM, Thierry Blanc [sed-users] wrote:
> I think Rakesh's piece of code shows the art of shell scripts. Shell
> scripting is cryptic and obscure on the first sight even for someone who
> knows scripting (geniuses excluded). This script could find its way to
> the Advanced Bash-Scripting Guide to show the power of shell. Its a
> true gem!
>
>>>
>>>> #!/bin/sh -u
>>>> c=3; # column to sed
>>>> d=\;; # csv delimiter character
>>>> code="
>>>> ${c}{
>>>> s/.*/\L&/;
>>>> s/\<[a-z]/\u&/g;
>>>> }
>>>> H;1h;\$!d;
>>>> g;y/\\n/$d/;
>>> > "
>>>
>>>
>>>
>>> > flag=
>>>> while IFS= read -r Line; do
>>>> case $flag in '' ) printf '%s\n' "$Line"; flag=1; continue;; esac;
>>>> set -f;
>>>> IFS=$d; set X $Line; shift;
>>>> printf '%s\n' "$@" | sed -e "$code";
>>>> done < input.csv
>>>
>>>
------------------------------------
------------------------------------
--
------------------------------------
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/