Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm have a very big data output in a .txt file that looks like this:

value1="1",value2="2",value3="test3",value4="4"
value1="1",value2="2",value3="anothertest3",value4="4"
value1="1",value2="2",value3="lasttest3",value4="4"

I want to extract the value within the quotation marks in value3, making the result look like this:

test3
anothertest3
lasttest3

How would I go about doing that?

share|improve this question

3 Answers 3

Sam's solution didn't work for me.

For the example data you provided, the following regex worked. It doesn't have any assumptions on length, other than that the value cannot contain a ", even if it's escaped (depending on your data's source, this was worth mentioning).

This also doesn't assume there is a value1 or value2 preceding it. They can be optionally omitted, or there can optionally be additional or otherwise unordered values.

  1. Search -> Replace (or Ctrl + h)
  2. Set search mode to Regular Expression
  3. Enter the following for the Find what field

    ^.*value3="([^"]*)".*$
    
  4. Set Replace with to $1

  5. Replace all
share|improve this answer

With Search Mode=Regular Expression

Search for: ^.*,value3="([^"]*)".*$
Replace with: \1

share|improve this answer
  1. Go to Search->Replace.
  2. Set Find what to ^value1=".*",value2=".*",value3="(.{10})",value4=".*"$.
  3. Set Replace with to \1.
  4. Set Search Mode to Regular expression.
  5. Press Replace All.
share|improve this answer
    
Thanks for the answer. I should've mentioned that all lines are different from eachother and contains different information in every variable. Also, they are not the same length or have the same amount of data. Also, the value I want to extract from every line, contains 10 characters. Is it possible to make it show the 10 chars after a certain text? –  lleroy Feb 7 '13 at 12:21
    
I've edited my answer to allow different values for value1, value2 and value4, and it now assumes value3 will be 10 characters long. –  Sam Feb 7 '13 at 23:12
    
Yes, it's possible to just show the 10 characters that follow value3=". To do so, use .*value3="(.{10}). The disadvantage of this is it doesn't account for the context since it's not actually parsing the data. For example, if a line was value1=",value3=",value121="",value3="anothertes", the expression would probably yield ,value121= instead of anothertes. –  Sam Feb 7 '13 at 23:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.