例如,我可能想要:
tail -f logfile | grep org.springframework | <command to remove first N characters>
我在想tr
可能有能力做到这一点,但我不确定。
使用cut
. 例如。去除每行的前 4 个字符(即从第 5 个字符开始):
tail -f logfile | grep org.springframework | cut -c 5-
sed 's/^.\{5\}//' logfile
然后你用你想要的数字替换 5 ......它应该可以解决问题......
编辑
如果为每一行
sed 's/^.\{5\}//g' logfile
您可以使用cut
:
cut -c N- file.txt > new_file.txt
-c:
人物
file.txt:
输入文件
new_file.txt:
输出文件
N-:
从 N 到结尾的字符被剪切并输出到新文件。
还可以有其他参数,如:'N'、'NM'、'-M' 分别表示第 n 个字符、第 n 个到第 m 个字符、第一个到第 m 个字符。
这将对输入文件的每一行执行操作。
tail -f logfile | grep org.springframework | cut -c 900-
将删除前 900 个字符
cut
使用 900- 显示第 900 个字符到行尾
但是,当我通过 grep 管道所有这些时,我什么也得不到
我认为awk
这将是最好的工具,因为它可以过滤并在过滤后的行上执行必要的字符串操作功能:
tail -f logfile | awk '/org.springframework/ {print substr($0, 6)}'
或者
tail -f logfile | awk '/org.springframework/ && sub(/^.{5}/,"",$0)'