例如,我可能想:
tail -f logfile | grep org.springframework | <command to remove first N characters>
我在想tr可能有能力做到这一点,但我不确定。
例如,我可能想:
tail -f logfile | grep org.springframework | <command to remove first N characters>
我在想tr可能有能力做到这一点,但我不确定。
当前回答
下面是一个简单的函数,在bash中测试。函数的第一个参数是字符串,第二个参数是要剥离的字符数
function stringStripNCharsFromStart {
echo ${1:$2:${#1}}
}
用法:
$ stringStripNCharsFromStart "12abcdefgh-" 2
# 2abcdefgh-
截图:
其他回答
tail -f logfile | grep org.springframework | cut -c 900-
会删除前900个字符吗
Cut使用900-显示到行尾的第900个字符
然而,当我通过grep管道所有这些,我什么也得不到
使用切割。如。剥离每行的前4个字符(即从第5个字符开始):
tail -f logfile | grep org.springframework | cut -c 5-
下面是一个简单的函数,在bash中测试。函数的第一个参数是字符串,第二个参数是要剥离的字符数
function stringStripNCharsFromStart {
echo ${1:$2:${#1}}
}
用法:
$ stringStripNCharsFromStart "12abcdefgh-" 2
# 2abcdefgh-
截图:
x=hello
echo ${x:1}
了喂
根据需要将1替换为N
sed 's/^.\{5\}//' logfile
然后把5换成你想要的数字…这应该能奏效……
编辑 如果对于每一行 sed的s / ^。5 \ \ {} / / g的日志文件