Using sed, how do you print the first 'N' characters of a line?

Berlin Brown picture Berlin Brown · Feb 11, 2009 · Viewed 160.6k times · Source

Using sed what is an one liner to print the first n characters? I am doing the following:

grep -G 'defn -test.*' OctaneFullTest.clj  | sed ....

Answer

Paul Tomblin picture Paul Tomblin · Feb 11, 2009

Don't use sed, use cut:

grep .... | cut -c 1-N

If you MUST use sed:

grep ... | sed -e 's/^\(.\{12\}\).*/\1/'