How can I extract the usernames and hosts from a .txt file

1 Ansicht (letzte 30 Tage)
Hello there! not an urgent question but I'm wondering if someone know how to extract the username,host,time only from a .txt file
Below is the sample .txt file named 'data_file.txt' - medhurst2732 [21/Jun/2019:15:45:49 -0700] "HEAD /scale/global/leverage HTTP/1.0" 203 15844 - dubuque8645 [21/Jun/2019:15:45:50 -0700] "POST /innovative/roi/robust/systems HTTP/1.1" 406 29046 - price5585 [21/Jun/2019:15:45:53 -0700] "GET /incubate/incubate HTTP/1.1" 201 12126 - [21/Jun/2019:15:45:54 -0700] "GET /convergence HTTP/2.0" 404 23856 - kshlerin3090 [21/Jun/2019:15:45:57 -0700] "HEAD /convergence HTTP/2.0" 501 16287 - [21/Jun/2019:15:46:00 -0700] "PUT /optimize HTTP/1.1" 401 13160
We are only taught simple extracting of numbers but not this level of work. Again, this is not an urgent question. Thank you
sample output:
username: medburst2732
time: 21/Jun/2019:15:45:49 -0700
username: dubuque8645
time:21/Jun/2019:15:45:50 -0700

Akzeptierte Antwort

Sudhakar Shinde
Sudhakar Shinde am 27 Okt. 2020
You can use readtable to read text file into table format.
file = 'data_file.txt';
opts = detectImportOptions(file );
Then You can extract Host, username and time data:
Host= T.Var1;
Username = T.Var3;

Weitere Antworten (0)


Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange



Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by