如何使用sed从字符串中去除前X个字符? [英] How can I strip first X characters from string using sed?
本文介绍了如何使用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屋!
查看全文