从括号中提取字符串 [英] Extract string from brackets

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

问题描述

我是 bash 的新手,所以这是一个非常菜鸟的问题..

I'm pretty new at bash so this is a pretty noob question..

假设我有一个字符串:

string1 [string2] string3 string4

我想从方括号中提取string2;但括号可以在任何其他时间包围任何其他字符串.

I would like to extract string2 from the square brackets; but the brackets may be surrounding any other string at any other time.

我将如何使用 sed 等来做到这一点?谢谢!

How would I use sed, etc, to do this? Thanks!

推荐答案

试试这个:

echo $str | cut -d "[" -f2 | cut -d "]" -f1

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

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