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

조회 수: 3 (최근 30일)
Joshua Mikhael Prieto
Joshua Mikhael Prieto 2020년 10월 27일
댓글: Sudhakar Shinde 2020년 10월 27일
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

채택된 답변

Sudhakar Shinde
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 CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by