Loading...

Include first line in grep

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

I want to grep this output for postgresql, but want to keep the column headers.

$ oc get pvc
NAME                                       STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS       AGE
elasticsearch-persistent-elasticsearch-0   Bound     pvc-56d17d9d-0bae-11ea-90a8-005056ab11cb   10Gi       RWO            vsphere-standard   1d
postgresql                                 Bound     pvc-9edfc710-0b9c-11ea-90a8-005056ab11cb   30Gi       RWO            vsphere-standard   1d

We use an alternate pattern, i.e. the first column name NAME.

$ oc get pvc | grep -E 'NAME|postgresql'
NAME                                       STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS       AGE
postgresql                                 Bound     pvc-9edfc710-0b9c-11ea-90a8-005056ab11cb   30Gi       RWO            vsphere-standard   1d
Please remember the terms for blog comments.