Sed failed to match non whitespace characters with character class

前端 未结 3 864
名媛妹妹
名媛妹妹 2021-01-15 06:29

I want to extract filter rules configured in /etc/lvm/lvm.conf, like filter = [ \"r|/dev/sda|\" ]. I want sed to return \"r|/dev

3条回答
  •  再見小時候
    2021-01-15 07:01

    Alternatively easier and shorter than [^[:space:]] you can do with \S+ without using brackets []

    \S means non whitespace char

    echo ' filter = [ "r|/dev/sda|" ] ' | sed -r 's:^\s*filter\s*=\s*\[\s*(\S+)\s*\]:\1:g'
    

    https://ideone.com/PxDX1Q

提交回复
热议问题