Linux: truncate all lines in a file

I had the following problem. I was analyzing a dump of a Java process. There was a String object taking a few hundred megabytes of heap. I saved it to a file and wanted to look at it. This string contained a few hundred lines many of them were very long. It’s not so easy to scroll through such a file. Actually, only the beginning of each line was interesting since the rest of the line contained only a huge list of ascii codes.

Here is how you get only the first 30 characters of each lines:


It’s actually pretty easy ! Just love how much you can actually do with a one liner as soon as you’ve found out whether you need to use grep, awk, sed, cut, tr or a combination of them !

Leave a Reply

Your email address will not be published.