如何使用 sed 从字符串中删除前 X 个字符? [英] How can I strip first X characters from string using sed?

查看:22
本文介绍了如何使用 sed 从字符串中删除前 X 个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个小型工业盒子中为嵌入式 Linux 编写 shell 脚本.我有一个包含文本 pid: 1234 的变量,我想从行中去除前 X 个字符,所以只有 1234 保留.我有更多的变量需要清理",所以我需要删除 X 个第一个字符,并且 ${string: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.

我正在尝试使以下内容起作用:

I am trying to make the following to work:

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

有什么想法吗?

推荐答案

这也能做到:

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

这篇关于如何使用 sed 从字符串中删除前 X 个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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