tags:

views:

3242

answers:

5

With sed, what is a one liner to print the first n characters. I am doing the following.

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

+5  A: 

Don't use sed, use cut.

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

If you MUST use sed:

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

For more complex processing, I recommend writing a quick awk script. It's a handy skill to have from time to time. Sorry no code right now. But that is easy in awk.

tkotitan
this post is not useful without an example.
SiegeX
A: 

Strictly with sed:

grep ... | sed -e 's/^\(.\{N\}\).*$/\1/'
Diego Sevilla
+2  A: 

don't have to use grep either

an example:

sed -n '/searchwords/{s/^\(.\{12\}\).*/\1/g;p}' file
A: 

It works just wonderfull thank you !!!!!

Ingles