Using sed, how do you print the first 'N' characters of a line?
Don't use sed
, use cut
:
grep .... | cut -c 1-N
If you MUST use sed
:
grep ... | sed -e 's/^\(.\{12\}\).*/\1/'
colrm x
For example, if you need the first 100 characters:
cat file |colrm 101
It's been around for years and is in most linux's and bsd's (freebsd for sure), usually by default. I can't remember ever having to type apt-get install colrm
.