简体   繁体   中英

How to open file in java and parse each line

I have a text file containing data like this:

sender id: 1/sequence number: 0/depth: 600/sending time: 13/05/2018 11:17:17 ص/data: Hello I am AUV: 1 this is aggregation # 0 from my sideEnd-End Delay:0.357072263241232 sender id: 0/sequence number: 0/depth: 700/sending time: 13/05/2018 11:17:17 ص/data: Hello I am AUV: 0 this is aggregation # 0 from my sideEnd-End Delay:0.293693984840975 sender id: 2/sequence number: 0/depth: 500/sending time: 13/05/2018 11:17:17 ص/data: Hello I am AUV: 2 this is aggregation # 0 from my sideEnd-End Delay:0.421466419584594 sender id: 3/sequence number: 0/depth: 400/sending time: 13/05/2018 11:17:17 ص/data: Hello I am AUV: 3 this is aggregation # 0 from my sideEnd-End Delay:0.486473186901286 sender id: 3/sequence number: 1/depth: 400/sending time: 13/05/2018 11:17:18 ص/data: Hello I am AUV: 3 this is aggregation # 1 from my sideEnd-End Delay:0.486473186901286 sender id: 1/sequence number: 0/depth: 600/sending time: 13/05/2018 11:17:21 ص/data: Hello I am AUV: 1 this is aggregation # 0 from my side End-End Delay:0.32221205728025 sender id: 0/sequence number: 0/depth: 700/sending time: 13/05/2018 11:17:21 ص/data: Hello I am AUV: 0 this is aggregation # 0 from my sideEnd-End Delay:0.267329486404354

Each line ends with the end-end delay, for example line#1:

sender id: 1/sequence number: 0/depth: 600/sending time: 13/05/2018 11:17:17 ص/data: Hello I am AUV: 1 this is aggregation # 0 from my sideEnd-End Delay:0.357072263241232

I need to divide this file into others files where each file corresponding to a specific sender id.

Each file will contain the end-end delay values for each sender id only such as 0.357072263241232.

I have 4 senders so 4 files will be generated ...

Any help or any hint please ?

I don't have the experience with regex!

Try Regex: sender\\sid:\\s(\\d+).*?End-End\\sDelay:(\\d+(?:\\.\\d+)?)

Demo

Group 1 will have the sender id

Group 2 will have the end - end delay value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM