如何截断STDIN线长? [英] How to truncate STDIN line length?

查看:89
本文介绍了如何截断STDIN线长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在解析一些日志文件,发现有些行太长而无法在一行上显示,因此Terminal.app请将它们包装到下一行。但是,我一直在寻找一种在一定数量的字符后截断行的方法,以使Terminal不会换行,从而更容易发现样式。

I've been parsing through some log files and I've found that some of the lines are too long to display on one line so Terminal.app kindly wraps them onto the next line. However, I've been looking for a way to truncate a line after a certain number of characters so that Terminal doesn't wrap, making it much easier to spot patterns.

我编写了一个小的Perl脚本来执行此操作:

I wrote a small Perl script to do this:

#!/usr/bin/perl

die("need max length\n") unless $#ARGV == 0;

while (<STDIN>)
{
    $_ = substr($_, 0, $ARGV[0]);
    chomp($_);
    print "$_\n";
}

但是我感觉到此功能可能已内置在其他工具中( sed?)我只是对这个任务不了解。

But I have a feeling that this functionality is probably built into some other tools (sed?) That I just don't know enough about to use for this task.

所以我的问题有点相反:我如何截断一行stdin

So my question sort of a reverse question: how do I truncate a line of stdin Without writing a program to do it?

推荐答案

将管道输出到:

cut -b 1-LIMIT

其中LIMIT是所需的线宽。

Where LIMIT is the desired line width.

这篇关于如何截断STDIN线长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆