# Use a variable from one grok to another for all lines from a log file

**URL:** <https://discuss.elastic.co/t/use-a-variable-from-one-grok-to-another-for-all-lines-from-a-log-file/256470>\
**Category:** Logstash\
**Created:** [November 24, 2020, 8:58am UTC](https://discuss.elastic.co/t/use-a-variable-from-one-grok-to-another-for-all-lines-from-a-log-file/256470 "2020-11-24T08:58:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blazkowicz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/blazkowicz/32/79589_2.png) [@Blazkowicz](https://discuss.elastic.co/u/Blazkowicz)\
**Post date:** [November 24, 2020, 8:58am UTC](https://discuss.elastic.co/t/use-a-variable-from-one-grok-to-another-for-all-lines-from-a-log-file/256470/1 "2020-11-24T08:58:56Z")

</div>

Hi all,

I have searched the forum for this type of question but what I have found I did not manage to make use of it. I am a newbie in all of ELK stack. Any help would be highly appreciated.

I have the following log type:

```auto
PROCESS=process_name; DEPLOY-DIR=/home/build/stuff/; PID=12345; started at 10:00:00 and stopped at 10:01:00
[......]
 INFO[10:00:01,184] - Config - Log4j property configuration chosen
[......]
 INFO[10:00:02,801] - ConnectionFactory - Initializing...
[......]

```

One of my logstash config that I tried looks like this:

```auto
input {
  beats {
    port => 5044
  }
}

filter {
  grok {
    match => { ["message" => "PROCESS=%{GREEDYDATA:job}; DEPLOY-DIR=%{GREEDYDATA:deploydir}; PID=%{BASE10NUM:pid}; started at %{TIME:process_start} and stopped at %{TIME:process_end}"] }
       }
  grok {
    match => { ["message" => "%{LOGLEVEL:loglevel}\[.*\] - %{WORD:class} - %{GREEDYDATA:message}"] }
    add_field => {["job_name" => "%{job}"]}
       }
  if "_grokparsefailure" in [tags] {
    drop { }
    }
}

output {
  elasticsearch {
    hosts => ["server_name:9200"]
    manage_template => false
    index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
    document_type => "%{[@metadata][type]}"
  }
}

```

What I'am trying to achieve, is to add a new field, called job (taken from the first line of the log), to the rest of the lines from that log.

Can I achieve this? I tried multiple types of filters but I cannot seems to have job populated for every row from that log file. Thank you.

---

<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:** [December 22, 2020, 8:59am UTC](https://discuss.elastic.co/t/use-a-variable-from-one-grok-to-another-for-all-lines-from-a-log-file/256470/2 "2020-12-22T08:59:09Z")

</div>

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