CSV data manipulation: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Sidef}}: Fix link: Perl 6 --> Raku) |
|||
Line 4,107: | Line 4,107: | ||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
{{works with|bash}} |
{{works with|bash}} |
||
Very simple solution using powerfull and ancient but strong linux command, I named "tr", and intern variable bash test capabilities : |
|||
<lang cat csv | while read S; do |
|||
[ -z ${S##*C*} ] && echo $S,SUM || echo $S,`echo $S | tr ',' '+' | bc` |
|||
done</lang> |
|||
Result : |
|||
<lang C1,C2,C3,C4,C5,SUM |
|||
1,5,9,13,17,45 |
|||
2,6,10,14,18,50 |
|||
3,7,11,15,19,55 |
|||
4,8,12,16,20,60</lang> |
|||
Other solution : |
|||
<lang bash>exec 0<"$1" # open the input file on stdin |
<lang bash>exec 0<"$1" # open the input file on stdin |
||
exec 1>"$1.new" # open an output file on stdout |
exec 1>"$1.new" # open an output file on stdout |