Linux
刪除模式之前的所有內容,並刪除符號
在這種模式下,我有超過 300 行包含來自 Jenkins 外掛的文本:
Server Sent Events (SSE) Gateway Plugin (sse-gateway): 1.24 Common API for Blue Ocean (blueocean-commons): 1.24.4 Handy Uri Templates 2.x API Plugin (handy-uri-templates-2-api): 2.1.8-1.0 Durable Task Plugin (durable-task): 1.35 Git Pipeline for Blue Ocean (blueocean-git-pipeline): 1.24.0 REST API for Blue Ocean (blueocean-rest): 1.24.4 Terraform Plugin (terraform): 1.0.10 GIT server Plugin (git-server): 1.9 Web for Blue Ocean (blueocean-web): 1.24.0 Bitbucket Pipeline for Blue Ocean (blueocean-bitbucket-pipeline): 1.24.0
我正在尋找一種方法來修剪不必要的文本,例如使用
sed
或之類的工具awk
,並得到如下結果:- plugin-util-api:1.7.0 - blueocean-pipeline-api-impl:1.24.0 - credentials-binding:1.24 - Pipelineworkflow-aggregator:2.6 - hashicorp-vault-plugin:3.6.1 - matrix-project:1.18 - blueocean-display-url:2.4.1 - structs:1.21
你可以試試這個:
$ sed 's/^.*(\([^()]*\)): \(.*\)$/- \1:\2/' file - sse-gateway:1.24 - blueocean-commons:1.24.4 - handy-uri-templates-2-api:2.1.8-1.0 - durable-task:1.35 - blueocean-git-pipeline:1.24.0 - blueocean-rest:1.24.4 - terraform:1.0.10 - git-server:1.9 - blueocean-web:1.24.0 - blueocean-bitbucket-pipeline:1.24.0
$ awk -F'[(): ]+' '{print "-", $(NF-1)":"$NF}' file - sse-gateway:1.24 - blueocean-commons:1.24.4 - handy-uri-templates-2-api:2.1.8-1.0 - durable-task:1.35 - blueocean-git-pipeline:1.24.0 - blueocean-rest:1.24.4 - terraform:1.0.10 - git-server:1.9 - blueocean-web:1.24.0 - blueocean-bitbucket-pipeline:1.24.0