使用Sed提取字符串的一部分 [英] Extract part of a string using Sed

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

问题描述

我想使用"Sed"实用程序提取字符串的第一部分. grep和awk在环境中不可用.输入为

I want to extract first part of a string using "Sed" utility. grep and awk are not available in the environment. The input is

" https://jintestexample.example.com/services/get/latest/accounts ".

我需要提取"/services"之前的字符串.我只需要使用sed.

I need to extract the string before "/services". I have to use sed only.

非常感谢您的帮助 谢谢, 金

Your help is much appreciated Thanks, Jin

推荐答案

只需删除/services以及以下内容:

Just remove /services and whatever follows:

echo "https://jintestexample.example.com/services/get/latest/accounts" \
| sed -e 's%/services.*%%'

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

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