4

I have a huge text file. This file has many lines and most of them have more that N characters before end-line.

How can I use sed to truncate lines from Nth character until the end of line?

Note: Obviously after this operation maximum line length is N.

1 Answer 1

11

With sed you can do it like this:

sed 's/\(.\{1,80\}\).*/\1/'

To truncate to 80 columns. It's more readable with ERE (Extended Regular Expressions), enabled with -r in GNU sed:

sed -r 's/(.{1,80}).*/\1/'

But, you could do it more efficiently with cut:

cut -c 1-80
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .