I am working on a project where i have to parse through text files and pull relevant information from them to work with later.
I have created a regular expression to match the lines of text that have the relevant data, but I’m unsure how to pull the relevant information from the line and dump it into a new text file.
Here’s a sample from the text file i’m parsing:
[ 5] local 10.170.150.195 port 42507 connected with 184.72.63.139 port 5001
[ 4] local 10.170.150.195 port 42506 connected with 184.72.63.139 port 500
[ 1] 0.0- 1.0 sec 0.00 KBytes 50.00 Kbits/sec
In this sample the relevant information is “0.0- 1.0 sec” and 50.00 Kbits/sec.
Here’s my regular expression:
[ [0-6]] 0.0- 1.0 sec 0.00 KBytes [0-9]*.[0-9][0-9] Kbits/sec
Sorry if this is a trivial question, I’m fairly new to java…this is day 3…
Any and all help would be greatly appreciated.
Thank You
Open your input file using FileReader/BufferedReader.
Open your output file using FileWriter/BufferedWriter
Read one line at a time in
while loopusing Buffered reader into a StringWithin
while loop, match the read string against your regexIf match found, write the string in output file using you Buffered writer
Close all the readers/writers open.
EDIT: Sample code style 1 as below:
Sample Code Style 2 as below:
All the best!