E
E
Egor Mikheev2018-08-28 14:37:36
linux
Egor Mikheev, 2018-08-28 14:37:36

Is it possible to use a regular expression in the tail command to search for matching files and not lines in them?

There are many examples on the net on how to extract the necessary information from the logs found using the tail command using a regular expression.
But I'm wondering if it's possible to do something more than select all files in the path that have *
Source data:
- There are 2 files in the directory with a special label in the name => my_company

- /var/log/containers/user-sync-service-54d7487d98-rxx8p_my_company_user-sync-service-fee158b16774f94221d2e7e652042aa905444cf34b333e0c1f6b0638ae2e85f9.log
- /var/log/containers/kube-gelf-2rcf4_my_company_agent-50798dc1c159b1ff75d00ba4f3b12af752093c69b1ada2067527caefbed0adc2.log

- I need to display information from the file my_company_user-sync-service... or with other postfixes user-sync-service2, user-sync-service3, but I need to exclude the second file with the agent postfix
All I found
is tail /var/ log/containers/*my_company*.log
Information from both files is displayed accordingly.
Requirements:
- The request must be inline,
- The search can only be by the namespace that I used and, accordingly, the regular expression must contain constructions that exclude certain postfixes.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor Mikheev, 2018-08-28
@ogregor

- something like this happened, it's not beautiful, but it works

find . -regex ".*my_company.*" ! -regex ".*my_company_\(agent\).*\.log" | xargs tail

V
VoidVolker, 2018-08-28
@VoidVolker

tail /tmp/file.txt | grep "text or regex"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question