Bash script to calculate within a CSV with or without zero
0
votes
1
answer
72
views
I have a script here that I am working with.
I would now like to expand this.
POSIXLY_CORRECT=1 awk -F ';' -v OFS=';' '
{print $0, NR == 1 ? "Price" : $1 ? $1 : $3 * 1.2}' RJ10 Standard spiral;RJ10
This is what the result should look like
Sales Price;External ID;Cost;Internal reference;Name;Sales Description;Price
73;1000-04;141,35;1000-04;Jabra GN 1000 RHL Remote Handset Lifter;Manueller Lifter bzw. Hook-Switch;73
0;0440-729;61,72;0440-729;Jabra GN 1000 RHL, zbh. für Siemens Optiset; Siemens Optiset Telefone;74,064
215;2126-82-04;221,8;2126-82-04;Jabra 2100 Mono QD 3-in-1 Set;Typ: 82 E-STD, Noise-Cancelling Mikrofonarm: Flexibel;215
0;01.01.8800;11,3;01.01.8800;Jabra Kabel QD -> RJ10 Standard spiral;RJ10;13,56
I have now created calc.sh with the following content:
#!/bin/sh
POSIXLY_CORRECT=1 awk '
BEGIN { FS=OFS=";" }
{
if (NR == 1) val = "Price"
else val = ($9 ? $5 * 1.2 : $9)
print $0, val
}
' /test.csv
and I run the file like this:
calc.sh > /opt/price/result.csv
this is the result:
Sales Price;External ID;Cost;Internal reference;Name;Sales Description
;Price
73;1000-04;141,35;1000-04;Jabra GN 1000 RHL Remote Handset Lifter;Manueller Lifter bzw. Hook-Switch
;
0;0440-729;61,72;0440-729;Jabra GN 1000 RHL, zbh. für Siemens Optiset; Siemens Optiset Telefone
;
215;2126-82-04;221,8;2126-82-04;Jabra 2100 Mono QD 3-in-1 Set;Typ: 82 E-STD, Noise-Cancelling Mikrofonarm: Flexibel
;
0;01.01.8800;11,3;01.01.8800;Jabra Kabel QD -> RJ10 Standard spiral;RJ10;
1. Price is on the 2nd line. Why?
2. Can I also specify somewhere that Price should be output in column xx?
Asked by dima1002
(11 rep)
Apr 5, 2023, 06:02 AM
Last activity: Apr 11, 2023, 05:16 AM
Last activity: Apr 11, 2023, 05:16 AM