| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
> Of course, now it's very obscure, a huge
> negative, probably about as obscure as the perl solution. But at least
> you did it. The parameter-driven while-loop script would have to be
> fixed up not to operate on the first line, but I'm sure that could be
I already posted the parameter-driven while-loop script that doesn't operate on the first line.(shown below also).
When I posted the code, I tried to make it as modular as bash/sed would allow me to, thinking that it wouldn't be obscure. hmmm....
> This will ensure that the first line is not modified...
> #!/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
---In [email protected], <dgoldman@...> wrote :
That is quite a feat you did! Of course, now it's very obscure, a huge
negative, probably about as obscure as the perl solution. But at least
you did it. The parameter-driven while-loop script would have to be
fixed up not to operate on the first line, but I'm sure that could be
done (I'm not suggesting you do it!). Anyway, as usual, there are
several ways to do something, with advantages and disadvantages.
Daniel
On 12/12/2015 11:00 AM, [sed-users] wrote:
> Of course the while-loop script can also be made parameter driven:
>
>
> #!/bin/sh -u
>
>
> c=3; # column to sed
> d=\;; # csv delimiter
>
>
> lc_code="$c!b;s/.*/\L&/;s/\<[a-z]/\u&/g"; # sed code to lowercase
> pr_code="H;1h;\$!d;g;y/\\n/$d/"; # sed code to print line
>
>
> while IFS= read -r Line; do
> set -f;
> IFS=$d; set X $Line; shift;
> set X $(printf '%s\n' "$@" | sed -e "$lc_code"); shift;
> echo "$@" | sed -e "$pr_code";
> done < input.txt
>
>
>
> HTH
>
>
> -Rakesh
>
[Non-text portions of this message have been removed]