我如何使用SED剥去字符串第一个X字符shellscript里? [英] How can I strip first X characters from string in shellscript using SED?

查看:159
本文介绍了我如何使用SED剥去字符串第一个X字符shellscript里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个小盒子工业编写shell脚本的嵌入式Linux。我有一个包含文本变量PID:1234,我想从行剥离第一个X字符,所以只有1234停留。我有更多的变数,我需要干净的,所以我需要切掉x第一个字符和$ {字符串:5}。不因为某些原因在我的系统中工作。

I am writing shell script for embedded Linux in a small industrial box. I have a variable containing the text "pid: 1234" and I want to strip first X characters from the line, so only 1234 stays. I have more variables I need to "clean", so I need to cut away X first characters and ${string:5} doesn't work for some reason in my system.

箱子好像有唯一的事情就是SED。

The only thing the box seems to have is SED.

我想作以下工作:

result=`echo "$pid" | sed 's/^.\{4\}//g'`

任何想法?

推荐答案

这将做的工作太多:

echo "$pid"|awk '{print $2}'

这篇关于我如何使用SED剥去字符串第一个X字符shellscript里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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