File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes Extracting only Matched string in linux Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Reply Bookmark "Extracting only Matched string in linux" Watch "Extracting only Matched string in linux" New topic
Author

Extracting only Matched string in linux

rajesh thiru
Greenhorn

Joined: May 24, 2010
Posts: 2
New to Linux, I need help from the guru's is it possible to extract only the matched string per line, for eg.,

<message><v></v><v></v><v></v><v>26.00000</v><v>-27.00000</v></message>
<message><v></v><v></v><v></v><v>26.00000</v><v>-27.00000</v></message>
<message><v></v><v></v><v></v><v>26.00000</v><v>-27.00000</v></message>


I need a way to extract like this

26.00000,-2700000
26.00000,-2700000
26.00000,-2700000


any help or suggestion will be appreciated..


regards
rajesh

Kees Jan Koster
Ranch Hand

Joined: Mar 31, 2009
Posts: 222
Dear Rajesh,

Looks like the input is XML. You can use XSLT to get data out in the format you want.

Kees Jan


Java-monitor, JVM monitoring made easy (and free)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14491
    
    7

Welcome to the JavaRanch, Rajesh.

There's several ways to do it. If the XML is neatly formatted and the data is one row per line, you can use one of the regular-expression based utilities such as sed, perl, awk or python to do the work. I did this, in fact, just yesterday. If you don't know how to use regular expressions, they're one of the most valuable things you can learn in a Linux/Unix environment.

Another alternative is to use XSL, which actually processes and parses the XML itself. Many Linux systems come with an "xsltproc" utility program that can be used. XSL code is more readable than regexes, although for me, it requires a lot of work.

A third alternative is to use an XML parsing package. There are XML parsers for Perl, Python, Java, C and more. Java in particular has quite a few different ways to parse XML, from the simple SAX processor up to things like DOM, StaX, the Apache Digester, JAXB, and so forth.


Customer surveys are for companies who didn't pay proper attention to begin with.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

With scala, it's quiete easy:

xsl-solutions are to prefered, because they're agnostic to linefeeds in the string - however, in generated files, which just happen to not contain linefeeds, sed is much faster, but have a little bit a different quoting-policy which looks :

(the round braces are masked here).


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Extracting only Matched string in linux
 
Similar Threads
How to get previous URL to current URL in spring MVC portlet
What is wrong with the regex?
Design patterns....
to list all links
java parsing using regular expression