Limit string length with sed

Hi. I'm trying to learn sed. I want to limit the length of a string. I tried this:

sed -n 's/^\(...........................\).*/\1/p' textfile.txt

This works fine, but how do I give it as a range rather than putting a hundred dots?
I'd like to limit the number of characters to 144 for twitter. I'd like to stick to sed to learn it. Thanks.

Try this:

sed 's/^\(.\{144\}\).*/\1/g' textfile.txt

And if you want to learn sed this would be a good place to start:

http://www.grymoire.com/Unix/Sed.html

Good Luck

1 Like

Try : something like this

$ echo "123456789101112131415" | sed 's/^.\{5\}//g'
6789101112131415

$ echo "123456789101112131415" | sed 's/^.\{8\}//g'
9101112131415

$ echo "123456789101112131415" | sed 's/^.\{10\}//g'
01112131415
1 Like

Thank you both!