Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何删除字符串开头和结尾的双引号_Bash_Shell_Sed_Grep - Fatal编程技术网

Bash 如何删除字符串开头和结尾的双引号

Bash 如何删除字符串开头和结尾的双引号,bash,shell,sed,grep,Bash,Shell,Sed,Grep,我的字符串包含双引号,如下所示: "[{"clientid":"*", "identityzone":"*"}]" 我想使用set或grep删除开头和结尾的双引号,输出应如下所示: [{"clientid":"*", "identityzone":"*"}] 我使用了:sed-e's/\“//g',但是这会删除字符串中所有的“,您需要使用线锚 $ echo '"[{"clientid":"*", "identityzone":"*"}]"' | sed 's/^"//; s/"$//' [{

我的字符串包含双引号,如下所示:

"[{"clientid":"*", "identityzone":"*"}]"
我想使用
set
grep
删除开头和结尾的双引号,输出应如下所示:

[{"clientid":"*", "identityzone":"*"}]

我使用了:
sed-e's/\“//g'
,但是这会删除字符串中所有的
,您需要使用线锚

$ echo '"[{"clientid":"*", "identityzone":"*"}]"' | sed 's/^"//; s/"$//'
[{"clientid":"*", "identityzone":"*"}]
  • ^“
    仅在行首匹配
  • “$
    仅在行尾匹配
  • 您还可以使用
    将它们组合为
    sed的//^“\\\\”$//g'
简单:

sed 's/^\"\(.*\)\"$/\1/g' <<<'"[{"clientid":"*", "identityzone":"*"}]"'
sed的//^\\”\(.*\)\“$//\1/g'
sed-i.bak-E的//^”|“$//g”文件