0

I have long lines with information in a file. I need help to be able to search on specific information and extract only that part of the line.

The script need to work through a batch file, but I don't know if batch is the optimal language for this task.

Info.txt:

Time=20130101|Info=ok|Hello=1234321|Result=sunnyweather|Numbers=cow|File=hello.txt....
Time=20130532|Info=ok|Hello=78654321|Result=badweather|Numbers=horse|File=one.wav....

So I need to be able to extract for example the "Result=..." and export to another file.

Which scripting language would you propose and how?

Thanks on beforehand! :)

2 Answers2

2

you should use sed:

>echo("Time=20130101|Info=ok|Hello=1234321|Result=sunnyweather|Numbers=cow|File=hello.txt...."|sed -r "s/.*(Result=\w+).*/\1/"
Result=sunnyweather

sed for Windows.

Endoro
  • 37,015
  • 8
  • 50
  • 63
1

How many lines do you have?

Hundreds:

If Exist Result.txt Del Result.txt
For /F "Tokens=4 Delims=^|" %%i In (Info.txt) Do Echo %%i>>Result.txt

Thousands or more:

Consider using SQLite shell (http://www.sqlite.org/sqlite.html).

LS_ᴅᴇᴠ
  • 10,823
  • 1
  • 23
  • 46