在bash中提取两个引号之间的字符串 [英] extracting a string between two quotes in bash

查看:42
本文介绍了在bash中提取两个引号之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有像这样的示例字符串测试"checkin_resumestorevisit-Online_V2.mt"运行

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

,我想提取bash中两个引号之间的文本.我尝试使用类似的命令

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

SUBSTRING=${echo $SUBSTRING| cut -d'"' -f 1 }

,但失败,并出现错误:错误替换.

推荐答案

为了提取引号之间的子字符串,可以使用以下替代方法之一:

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

替代1:

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

替代2:

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

替代3:

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

这篇关于在bash中提取两个引号之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆