How can I extract the usernames and hosts from a .txt file
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Joshua Mikhael Prieto
el 27 de Oct. de 2020
Comentada: Sudhakar Shinde
el 27 de Oct. de 2020
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'
103.247.168.212 - medhurst2732 [21/Jun/2019:15:45:49 -0700] "HEAD /scale/global/leverage HTTP/1.0" 203 15844
57.86.153.68 - dubuque8645 [21/Jun/2019:15:45:50 -0700] "POST /innovative/roi/robust/systems HTTP/1.1" 406 29046
219.133.7.154 - price5585 [21/Jun/2019:15:45:53 -0700] "GET /incubate/incubate HTTP/1.1" 201 12126
159.252.184.44 - [21/Jun/2019:15:45:54 -0700] "GET /convergence HTTP/2.0" 404 23856
40.167.172.66 - kshlerin3090 [21/Jun/2019:15:45:57 -0700] "HEAD /convergence HTTP/2.0" 501 16287
115.214.173.248 - [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
host: 103.247.168.212
time: 21/Jun/2019:15:45:49 -0700
username: dubuque8645
host: 57.86.153.68
time:21/Jun/2019:15:45:50 -0700
0 comentarios
Respuesta aceptada
Sudhakar Shinde
el 27 de Oct. de 2020
You can use readtable to read text file into table format.
file = 'data_file.txt';
opts = detectImportOptions(file );
T=readtable(file,opts);
Then You can extract Host, username and time data:
Host= T.Var1;
Username = T.Var3;
Time=T.Var4
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!