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.
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";
}
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.
So my question sort of a reverse question: how do I truncate a line of stdin Without writing a program to do it?
Select a blank cell next to the string you want to truncate, and enter this formula =LEFT(A1,6) (A1 is the string you use, and 6 indicates truncate the string into six characters), then drag fill handle over the cells which also need this formula.
The text can also be truncated using the CSS ::after pseudo-element. In the next example, the overflow of the <span> is hidden, and the max-height is set based on the line-height . Example of truncating a multi-line text using the ::after pseudo-element: ¶
If there is a need for spacing around the truncated text, padding must be applied to the parent element. The text can also be truncated using the CSS ::after pseudo-element. In the next example, the overflow of the <span> is hidden, and the max-height is set based on the line-height.
By ignoring this, we might trim the string to fewer than 10 code points, or (worse) truncate it in the middle of a surrogate pair. On the other hand, String.length () is not a good measure of Unicode text length, so trimming based on that property may be the wrong thing to do.
Pipe output to:
cut -b 1-LIMIT
Where LIMIT is the desired line width.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With