Query about conditional pattern matching
Hello All,
I am trying to count the number of users logged in a particular day using the last and filtering with 'awk, like below: Code:
last | awk '/Mar 12/{count n++}END{print n}' Is there any sub-programming in awk or sed to a) print the lines that contain the pattern b) stop parsing the file, once the line that does not contain pattern had been reached. |
Maybe use the -F option for last and then limit the regex to be between the dates you are looking for.
As for stop parsing the file, you can use the exit command when you reach the point at which you wish to stop. |
Hi Grail,
Thanks for the suggestions!. I added the 'day of the week' in the regex and excluded the previous year's information from the output Code:
last | awk '/Mon Mar 11/{count n++}END{print n}' Code:
last | sed '1,/<PREVIOUS DATE>/!d' | sed -n '/<REQUIRED DATE>/p' | wc -l Thank you once again! |
hmmm ... my suggestion was the option for last not awk, just to be clear.
|
All times are GMT -5. The time now is 05:04 PM. |