How can I extract the usernames and hosts from a .txt file
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Sudhakar Shinde
2020-10-27
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!