Extracting information from a string using regex in bash

前端 未结 2 1136
眼角桃花
眼角桃花 2021-01-28 12:13

I have a string variable in bash which looks like so:

{\"SOGoTimeFormat\": \"%H:%M\", \"SOGoMailShowSubscribedFoldersOnly\": \"0\", \"SOGoMailSignaturePlacement\         


        
2条回答
  •  时光取名叫无心
    2021-01-28 12:57

    jq is an excellent tool for parsing and editing JSON, easy to drive from shell.

    # extract "enabled" field from "Forward"
    enabled=$(jq '.Forward.enabled` 

    ...or, to do the whole thing in one pass:

    jq '
      if .Forward.enabled==1 then
        .Forward.forwardAddress=[(
          .Forward.forwardAddress[] |
          select(. | test("testuser2") | not)
        )]
      else . end
    ' output.json
    

提交回复
热议问题