B
B
Boris Dergachev2014-11-18 11:28:03
Debian
Boris Dergachev, 2014-11-18 11:28:03

How to form a regular expression?

There is a text file containing a log of package manager actions (for Debian /var/log/dpkg.log). It is necessary to pull out from it the names of installed packages for the last three days. A few lines from the file:

2014-11-18 10:02:29 startup archives unpack
2014-11-18 10:02:29 install xutils-dev:amd64 <нет> 1:7.7~1
2014-11-18 10:02:29 status half-installed xutils-dev:amd64 1:7.7~1

For these lines, the result of the regular expression must be the single word "xutils-dev" (the architecture is optional).

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Lerg, 2014-11-18
@froex

Why do you need a regular expression here?
Here's a Python script for you:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

fromDate = '2014-11-15'

for line in open('/var/log/dpkg.log'):
  date, time, action, name, other = line.split(' ', 4)
  if date >= fromDate and action == "install":
    print(name)

Set the date from which to display and run the script.

O
OlegLazarenko, 2014-11-18
@OlegLazarenko

For example like this:
regex101.com/r/mB2xC0/1

S
Sergey Mishin, 2014-11-18
@sergeysmishin

(?=[a-zA-z])\b\w+-?\w+\b(?=:)
or
(install|installed) \w+-?\w+\b(?=:)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question