如何在unix中的特定字符后剪切字符串 [英] How to cut a string after a specific character in unix

查看:85
本文介绍了如何在unix中的特定字符后剪切字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个字符串:

$var=server@10.200.200.20:/home/some/directory/file

我只想提取目录地址,这意味着我只想要:"字符之后的位并获取:

I just want to extract the directory address meaning I only want the bit after the ":" character and get:

/home/some/directory/file

谢谢.

我需要一个通用命令,因此cut命令将无法工作,因为$ var变量没有固定的长度.

I need a generic command so the cut command wont work as the $var variable doesn't have a fixed length.

推荐答案

使用sed:

$ var=server@10.200.200.20:/home/some/directory/file
$ echo $var | sed 's/.*://'
/home/some/directory/file

这篇关于如何在unix中的特定字符后剪切字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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