V
V
Vadim2020-08-12 17:46:29
bash
Vadim, 2020-08-12 17:46:29

How to remove unnecessary from the output of a command?

Hey everyone,

the following command prints pods to the screen like this:
$ kubectl get pods -n mainspace

max-reporting-mrc-deployment-384743d45-spjnc 
max-reporting-mrc-deployment-6d9f966cf8-spjnc
npx-daemon-4njjs
npx-daemon-8h6nb


is it possible to process this output somehow with pipe and regex to get the output:

max-reporting-mrc-deployment 
max-reporting-mrc-deployment
npx-daemon
npx-daemon


that is, to remove that part of the line where the numeric characters after the dash begin?

all the best,
Vadim

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-08-12
@Viji

grep -oP '^[a-z]+(-[a-z]+)*'
grep -oP '^.+?(?=-\d|$)'
sed 's/-[0-9].*//'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question