# Bytes calulcation

**URL:** <https://discuss.elastic.co/t/bytes-calulcation/149096>\
**Category:** Logstash\
**Created:** [September 19, 2018, 9:54am UTC](https://discuss.elastic.co/t/bytes-calulcation/149096 "2018-09-19T09:54:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arun\_Murugappan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arun_murugappan/32/101630_2.png) [@Arun\_Murugappan](https://discuss.elastic.co/u/Arun_Murugappan)\
**Post date:** [September 19, 2018, 9:54am UTC](https://discuss.elastic.co/t/bytes-calulcation/149096/1 "2018-09-19T09:54:53Z")

</div>

configuration file:

input {  
file {  
path =\> "/home/murugar/Documents/denim.csv"  
type =\> "csv"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
}  
}

filter {  
csv{  
separator =\> ","  
columns =\> ["Index No:", "Memory"]  
}  
grok {  
# would like to put store\_units\_prefix and store\_units\_base in @metadata, too  
match =\> { "Memory" =\> "^%{BASE10NUM:[@metadata][store\_number]:float}(?\<store\_units\_prefix\>[kKmMgGtT])(?\<store\_units\_base\>[b])$" }  
}  
mutate {  
add\_field =\> {  
"[@metadata][store\_units\_prefix]" =\> "%{store\_units\_prefix}"  
"[@metadata][store\_units\_base]" =\> "%{store\_units\_base}"  
}  
remove\_field =\> ["store\_units\_prefix", "store\_units\_base"]  
}  
if [@metadata][store\_units\_prefix] == "k" or [@metadata][store\_units\_prefix] == "K" {  
mutate { add\_field =\> { "[@metadata][store\_multiplier]" =\> 1024 } }  
} else if [@metadata][store\_units\_prefix] == "m" or [@metadata][store\_units\_prefix] == "M" {  
mutate { add\_field =\> { "[@metadata][store\_multiplier]" =\> 1048576 } }  
} else if [@metadata][store\_units\_prefix] == "g" or [@metadata][store\_units\_prefix] == "G" {  
mutate { add\_field =\> { "[@metadata][store\_multiplier]" =\> 1073741824 } }  
} else if [@metadata][store\_units\_prefix] == "t" or [@metadata][store\_units\_prefix] == "T" {  
mutate { add\_field =\> { "[@metadata][store\_multiplier]" =\> 1099511627776 } }  
}

# I don't know how to specify type in mutate.add\_field, so I convert it

```
mutate {
    convert => { "[@metadata][store_multiplier]" => "integer" }
}

```

# create a new field with the size in bytes

mutate  
{  
**add\_field =\>{ "[store\_size]" =\> {"[@metadata][store\_number]" \* "[@metadata][store\_multiplier]"}}**  
}  
}

output {  
# elasticsearch{  
# hosts =\> "192.168.124.128:40200"  
# index =\> "csv2"  
# user =\> "es\_admin"  
# password =\> "#elk20#"  
# }

```
    stdout
    {

    codec => rubydebug
    }

    }

```

i am geeting error in the line for bolded one.

input file is a csv file:

1, 100 gb  
2, 2 kb  
3, 40 mb

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 17, 2018, 9:55am UTC](https://discuss.elastic.co/t/bytes-calulcation/149096/2 "2018-10-17T09:55:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
