If I type
echo '"";"";" 01.06.2011";"7";"01.06";"-21,00";"-6.097,73";' | awk -F';' '{print $3 " " $7}'
then I get
" 01.06.2011" "-6.097,73"
but what I would like is
" 01.06.2011" "-6097"
How should that be done?
AWK supports the printf function, and, from memory, parses as much of a string as an integer as it can. So, from your example:
awk -F';' '{printf("%s %i", $3, $7*1000);}'
would work. This will work for any size number, too…
(above doesn't work due to double quotes in the data, see below…)
EDIT: If you're using gawk, you can achieve this stably using a combination of printf and strtonum.
awk -F';' '{
gsub(/"/, "", $7);
printf("%s \"%i\"\n", $3, strtonum($7)*1000);
}'
The gsub()
call strips off the quotes so that strtonum
doesn't choke on them, and then the printf
call puts them back as part of the format string…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With