# Ingest pipeline to parse basename from path

**URL:** https://discuss.elastic.co/t/ingest-pipeline-to-parse-basename-from-path/205809
**Category:** Elasticsearch
**Created:** [October 30, 2019, 8:11am UTC](https://discuss.elastic.co/t/ingest-pipeline-to-parse-basename-from-path/205809 "2019-10-30T08:11:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bruce289](https://avatars.discourse-cdn.com/v4/letter/b/7bcc69/32.png) [@bruce289](https://discuss.elastic.co/u/bruce289)
#### Post date: [October 30, 2019, 8:11am UTC](https://discuss.elastic.co/t/ingest-pipeline-to-parse-basename-from-path/205809/1 "2019-10-30T08:11:19Z")

</div>

Hi,

I can't quite figure out how to use dissect/grok in an ingest pipeline to obtain the basename from a UNIX path. Basically, I would like each of the following inputs to return `{ "name" : "ssh" }`:

ssh  
bin/ssh  
/usr/bin/ssh

Thanks.

---

<div class="post-metadata">

### Author: ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)
#### Post date: [October 31, 2019, 12:22pm UTC](https://discuss.elastic.co/t/ingest-pipeline-to-parse-basename-from-path/205809/2 "2019-10-31T12:22:33Z")

</div>

I think you need a combination of two Grok patterns, to handle those situations where there is a slash and those where there is not. A combination of these patterns should work: `["^.*/%{DATA:name}$", "^%{DATA:name}$"]`

```auto
POST /_ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "grok": {
          "field": "input",
          "patterns": ["^.*/%{DATA:name}$", "^%{DATA:name}$"]
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "input": "ssh"
      }
    },
    {
      "_source": {
        "input": "bin/ssh"
      }
    },
    {
      "_source": {
        "input": "/usr/bin/ssh"
      }
    }
  ]
}

```

---

<div class="post-metadata">

### Author: ![bruce289](https://avatars.discourse-cdn.com/v4/letter/b/7bcc69/32.png) [@bruce289](https://discuss.elastic.co/u/bruce289)
#### Post date: [November 1, 2019, 12:47pm UTC](https://discuss.elastic.co/t/ingest-pipeline-to-parse-basename-from-path/205809/3 "2019-11-01T12:47:26Z")

</div>

Thanks, Abdon 👍

---

<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: [November 29, 2019, 12:47pm UTC](https://discuss.elastic.co/t/ingest-pipeline-to-parse-basename-from-path/205809/4 "2019-11-29T12:47:29Z")

</div>

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