从支架提取字符串 [英] Extract string from brackets

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

问题描述

我是pretty在打击新的,所以这是一个pretty noob问题。

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

假设我有一个字符串:

string1 [string2] string3 string4

我想在方括号中提取字符串2 ;但是托架可以是围绕在其他任何时间任何其他的字符串。

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天全站免登陆