extracting a string between two quotes in bash

前端 未结 3 746
被撕碎了的回忆
被撕碎了的回忆 2021-01-19 07:00

I have example string like Test \"checkin_resumestorevisit - Online_V2.mt\" Run

and i want to extract the text between the two quotes in bash. I tried

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-19 07:50

    In order to extract the substring between quotes you can use one of these alternatives:

    Alternative 1:

    SUBSTRING=`echo "$SUBSTRING" | cut -d'"' -f 2`
    

    Alternative 2:

    SUBSTRING=`echo "$SUBSTRING" | awk -F'"' '{print $2}'`
    

    Alternative 3:

    set -f;IFS='"'; SUBSTRING=($SUBSTRING); SUBSTRING=${SUBSTRING[1]};set +f
    

提交回复
热议问题