如何通过分隔符对字符串的某些部分进行 sed [英] how to sed for certain parts of a string by delimiter

查看:41
本文介绍了如何通过分隔符对字符串的某些部分进行 sed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多不同的字符串,看起来像 redhat-ubi-ubi7-7.8

我想使用字符串来创建变量,这样我最终会得到类似的东西

vendor=redhat产品=ubi图像=ubi7标签=7.8

我该怎么做?

解决方案

With bash 和一个 here string:

string='redhat-ubi-ubi7-7.8'IFS=- read -r 供应商产品图像标签<<<<;$字符串"回声$供应商"

输出:

<前>红色的帽子

I have lots of different strings that look like redhat-ubi-ubi7-7.8

I want to use the string to make variables so that I end up having something like

vendor=redhat
product=ubi
image=ubi7
tag=7.8

How can I do this?

解决方案

With bash and a here string:

string='redhat-ubi-ubi7-7.8'
IFS=- read -r vendor product image tag <<< "$string"
echo "$vendor"

Output:

redhat

这篇关于如何通过分隔符对字符串的某些部分进行 sed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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