bash:保存带有与列对齐的空间的选项卡
我正在尝试显示.tsv
文件很好地对齐为列,但允许将显示到当前屏幕宽度。我能够以以下方式完成此操作,但如果输入包含列
使用的特定字符,则将失败。我目前使用的当前解决方案如下:
bash$ cat sample.tsv | tr '\t' '@' | column -n -t -s @ | cut -c-`tput cols`
我尝试直接使用标签本身,但无法使其正常工作。对于列
的默认选项,使用任何whitespace,而不仅仅是选项卡,因此它对我不起作用。比上述更好的选择要感谢任何更好的选择。
PS: 样本如下
bash:~$ cat sample.tsv
Sl Name Number Status
1 W Jhon +1 234 4454 y
2 M Walter +2 232 453 n
3 S M Ray +1 343 453 y
bash:~$ cat sample.tsv | tr '\t' '@' | column -n -t -s @ | cut -c-`tput cols`
Sl Name Number Status
1 W Jhon +1 234 4454 y
2 M Walter +2 232 453 n
3 S M Ray +1 343 453 y
bash:~$ cat sample.tsv | column -n -t | cut -c-`tput cols`
Sl Name Number Status
1 W Jhon +1 234 4454 y
2 M Walter +2 232 453 n
3 S M Ray +1 343 453 y
bash:~$
I am trying to display .tsv
files aligned nicely as columns, and yet allow limiting display to the current screen width. I am able to get this done in the following way that works in general but will fail if the input contains a particular character that is used by column
. The current solution that I am using presently works as follows:
bash$ cat sample.tsv | tr '\t' '@' | column -n -t -s @ | cut -c-`tput cols`
I tried using tab itself directly but could not make it work. And with default option for column
, any whitespace and not just tabs are used so it does not work for me. Would be thankful for any better alternative than the above.
PS:
A sample is shown below
bash:~$ cat sample.tsv
Sl Name Number Status
1 W Jhon +1 234 4454 y
2 M Walter +2 232 453 n
3 S M Ray +1 343 453 y
bash:~$ cat sample.tsv | tr '\t' '@' | column -n -t -s @ | cut -c-`tput cols`
Sl Name Number Status
1 W Jhon +1 234 4454 y
2 M Walter +2 232 453 n
3 S M Ray +1 343 453 y
bash:~$ cat sample.tsv | column -n -t | cut -c-`tput cols`
Sl Name Number Status
1 W Jhon +1 234 4454 y
2 M Walter +2 232 453 n
3 S M Ray +1 343 453 y
bash:~$
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将列设置为将选项卡用作字符,用于用
-s
划定列:列-t -s $'\ t'-n sample.tsv
You can set column to use tab as character to be used to delimit columns with
-s
:column -t -s $'\t' -n sample.tsv