如何grep总是从具有特定文本的行改变的文本?

xyz*_*ala 4 command-line text-processing

contentJSON is :-
{"id":"0","name":"inc_timestamp","workspaceId":"37158928","infoJSON":"{a:{\"a\":\"bcd\",\"b\":{\"c\":\"d\"}}}","contentJSON":"{\n  \"tasks\": [\n    {\n      \"name\": \"Input\",\n      \"taskType\": \"executeCustomSQLQueryForIncrementalLoad\",\n      \"id\": 10,\n      \"x\": 95,\n      \"y\": 44,\n      \"inputConnectors\": [],\n      \"outputConnectors\": [\n        {\n          \"nodeID\": 11,\n          \"type\": \"Output\",\n          \"name\": \"\"\n        }\n      ],\n      \"argsMap\": {\n        \"taskId\": 10,\n        \"datasetId\": 49053696,\n        \"deltaColumnName\": \"timestamp\",\n        \"deltaColumnDataType\": \"timestamp\",\n        \"deltaColumnValue\": \"null\",\n        \"primaryKeysList\": [\n          \"id\"\n        ]\n      },\n      \"datasetId\": 49053696\n    },\n    {\n      \"name\": \"Output\",\n      \"taskType\": \"saveToES\",\n      \"id\": 11,\n      \"x\": 453,\n      \"y\": 44,\n      \"inputConnectors\": [\n        {\n          \"nodeID\": 10,\n          \"type\": \"Input\",\n          \"name\": \"\"\n        }\n      ],\n      \"outputConnectors\": [],\n      \"argsMap\": {\n        \"bizvizcubeId\": 46759937,\n        \"cfg\": {\n          \"es.mapping.id\": \"id\"\n        }\n      }\n    }\n  ],\n  \"connections\": [\n    {\n      \"source\": {\n        \"taskId\": 10,\n        \"connectorIndex\": 0\n      },\n      \"dest\": {\n        \"taskId\": 11,\n        \"connectorIndex\": 0\n      }\n    }\n  ],\n  \"isIncrementalLoadModeWorkflow\": 1\n}\n"}
Status:200
{"wokspaceResp":{"success":true,"workspaces":[],"params":"{\"id\":\"49086475\"}"}}
{"wokspaceResp":{"success":true,"workspaces":[],"params":"{\"id\":\"49086475\"}"}}
{"success":true,"workspaces":[],"params":"{\"id\":\"49086475\"}"}
{"id":"49086475"}
wfid is : 49086475
finally wfid is : 49086475
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.136s
[INFO] Finished at: Tue Oct 24 15:30:48 IST 2017
[INFO] Final Memory: 33M/392M
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

我需要 grep49086475每次执行我的程序时都会发生变化。

请指导我在finally wfid is :.

mur*_*uru 8

使用 awk:

awk '/finally wfid is :/{print $NF}'
Run Code Online (Sandbox Code Playgroud)

... 打印包含finally wfid is :.


pa4*_*080 7

grep以这种方式使用:

grep -oP 'finally wfid is : \K.*' <filename>
Run Code Online (Sandbox Code Playgroud)
  • 来源答案的解释:

    grep-P用于具有PCRE(解读图案作为P ERL- Ç ompatible ř egular È XPRESSION)和-o打印匹配的单独模式。该\K通知会忽略自己之前所匹配的部分来了。


或者你可以这样使用sed

sed -n 's/finally wfid is : //p' <filename>
Run Code Online (Sandbox Code Playgroud)
  • 此命令将仅打印包含 string 的行finally wfid is :,但它将被替换为空字符串。