Answer the question
In order to leave comments, you need to log in
How to find a word in a line of a file (bash)?
There is the following task: there is a log file which contains records about the users who used the server. Each line contains a record of one session (date, time, ip, user, etc.).
How can I extract the username from this file? it is known that all lines are ordered, i.e. the username is exactly between the 6th and 7th spaces.
log example:
Sun Oct 12 11:23:54 2016 101.45.x.x User ........... .. . . .
Answer the question
In order to leave comments, you need to log in
Alternatively, make a similar script using AWK:
cat filename.log | gawk 'BEGIN { FS=" " } // { print $7 }'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question