使用Bash删除文本文件中的列? [英] Removing columns in text file with Bash?
问题描述
我有一个要编写的脚本,用于从finger的输出中删除Idle列.
I have a to write a script that remove the Idle column from the output of finger.
>finger
Login Name TTY Idle Login Time Office Phone
Billy Billy Howard *con 6:55 Fri 19:03
Billy Billy Howard s00 5 Fri 19:11
Billy Billy Howard s00 Sat 00:27
我尝试用tr删除多余的空格,然后使用带有空格分隔符的cut来删除列,但是由于Idle可能没有值,所以我有时会得到错误的值,因为tr分隔了空格,因此空闲时间应为...有人知道我如何删除空闲"列吗?
I tried remove the extra spaces with tr and then using cut with a delimiter of a space to remove the column, but since Idle can have no value I sometimes get the wrong value since tr delimited the spaces were the idle time should be... Does anyone know how I can remove the Idle column?
推荐答案
此解决方案并不完美:列的位置和宽度可能会发生变化.如果它们恒定,则以下命令将通过删除包含在第34至39列的文本来解决问题:
This solution is not perfect: the column position and width might change. If they are constant, the following command will do the trick by removing text columns 34 to 39 inclusively:
finger | colrm 34 39
这篇关于使用Bash删除文本文件中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!