# Remove drive letter from file path GROK pattern

**URL:** <https://discuss.elastic.co/t/remove-drive-letter-from-file-path-grok-pattern/274609>\
**Category:** Elasticsearch\
**Created:** [June 1, 2021, 9:42am UTC](https://discuss.elastic.co/t/remove-drive-letter-from-file-path-grok-pattern/274609 "2021-06-01T09:42:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam3546](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sam3546/32/79281_2.png) [@sam3546](https://discuss.elastic.co/u/sam3546)\
**Post date:** [June 1, 2021, 9:42am UTC](https://discuss.elastic.co/t/remove-drive-letter-from-file-path-grok-pattern/274609/1 "2021-06-01T09:42:09Z")

</div>

Im trying to remove the drive letter from file paths as they are ingested through the pipeline, my input is something like

C:\folder1\folder2\file.ext  
(This is just an example the file could be many more folders deep)

I want the output to just be

folder1\folder2\file.ext

Im currently using  
%{GREEDYDATA:driveLetter}[:]%{GREEDYDATA:filePath}

This gives me the structure I want but by escaping the slashes it now has double the slashes between elements

folder1\\folder2\\file.ext

Any suggestions would be appreciated. Cheers

---

<div class="post-metadata">

**Author:** ![sam3546](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sam3546/32/79281_2.png) [@sam3546](https://discuss.elastic.co/u/sam3546)\
**Post date:** [June 1, 2021, 9:57am UTC](https://discuss.elastic.co/t/remove-drive-letter-from-file-path-grok-pattern/274609/2 "2021-06-01T09:57:00Z")

</div>

Replying to my own question, there may be a cleaner solution but using a gsub before the grok to replace the double \\ with a single / escapes the backslashing issue altogether.

```auto
"gsub": {
  "field": "input",
  "pattern": "\\\\",
  "replacement": "/"
},

```

---

<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:** [June 29, 2021, 9:57am UTC](https://discuss.elastic.co/t/remove-drive-letter-from-file-path-grok-pattern/274609/3 "2021-06-29T09:57:07Z")

</div>

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