Refine your search:

Hi,

I was wondering if it's possible to export search and table results in a txt file ? (with a script, a command, ...)

I've seen that was possible to export in json, xml and csv, but not in a txt file.

Thanks

asked 19 May '11, 08:04

aymericbrun's gravatar image

aymericbrun
10115
accept rate: 0%


4 Answers:

There are a few ways to do it.

From the GUI, you should also see a "Raw Events" as an export option along with json, xml, and csv.

From the search language, there are several ways to do it as well. Here is one example that will export to a text file, $SPLUNK_HOME/var/run/splunk/results.txt

outputtext usexml=false | rename _xml as raw | fields raw | fields - _* | outputcsv results.txt
link

answered 19 May '11, 10:06

bwooden's gravatar image

bwooden ♦
3.0k1310
accept rate: 38%

Hi,

I found this post very helpful! :)

I have a small question about it. Is there a way how to store the exported file in a different folder? Eg. in /tmp/ ?

Thanks a lot!

(03 Feb '12, 01:57) simonattardGO

+2 for you, works like a champ. Thanks!

(26 Jun '12, 09:23) miwalker

Works perfectly, great !

Thank you very much

link

answered 20 May '11, 00:58

aymericbrun's gravatar image

aymericbrun
10115
accept rate: 0%

I have another question :-)

Everytime i do that command, a new "results.txt" is created, witch replace (and erase) the last "results.txt". Is it possible to write at the end of this file ?

When i start this search, i'd like the results be added at the end of the file, to have a bigger and bigger file everytime i start the search.

Regards

link

answered 20 May '11, 02:45

aymericbrun's gravatar image

aymericbrun
10115
accept rate: 0%

outputcsv doesn't currently support an append. So we use it as an input, add a search to it, and the write the results out again...

|inputcsv results.txt | append [search * | head 10 | outputtext usexml=false | rename xml as raw | fields raw | fields - * ] | outputcsv results.txt

(20 May '11, 05:35) bwooden ♦

The above comment should have a '_' prefix before the xml and the asterik but were used to italicize the text between

(23 May '11, 06:19) bwooden ♦

Thank you for your quick answer, but the second command you wrote doesn't work. In fact, it works better than your first command, but the results are not appended to the existing results.txt. Splunk keeps creating a new "results.txt" witch contains the results of the last search, results are not added in the existing file.

Here's what i wrote:

inputcsv results.txt | append [search source="access_combined" | outputtext usexml=false | rename xml as raw | fields raw | fields - * ] | outputcsv results.txt

Have you an idea ?

Extra : I have a second problem, the search can't finalize because "subsearch auto-finalized after time limit (30 seconds) reached". I search how to disable this but i can't find anything !

link

answered 23 May '11, 02:18

aymericbrun's gravatar image

aymericbrun
10115
accept rate: 0%

edited 23 May '11, 05:53

You can prepend instead of append to eliminate the subsearch. NB: In below text, due to comment formatting, replace the two instances of ~ with a _

source="access_combined" | head 10 | outputtext usexml=false | rename ~xml as raw | fields raw | fields - ~* | append [|inputcsv results.txt ] | outputcsv results.txt

(23 May '11, 06:27) bwooden ♦

Thank you very much for your help! Now it works really well (thanks to your last answer)

(23 May '11, 06:53) aymericbrun
Post your answer
toggle preview

Follow this question

Log In to enable email subscriptions

RSS:

Answers

Answers + Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×1,685
×159
×113
×61
×1

Asked: 19 May '11, 08:04

Seen: 2,642 times

Last updated: 26 Jun '12, 09:23

Copyright © 2005-2012 Splunk Inc. All rights reserved.