What is a unix command for deleting the first N characters of a line?


Question

For example, I might want to:

tail -f logfile | grep org.springframework | <command to remove first N characters>

I was thinking that tr might have the ability to do this but I'm not sure.

1
196
8/18/2014 7:21:56 AM

Accepted Answer

Use cut. Eg. to strip the first 4 characters of each line (i.e. start on the 5th char):

tail -f logfile | grep org.springframework | cut -c 5-
304
6/9/2009 7:06:44 PM

sed 's/^.\{5\}//' logfile 

and you replace 5 by the number you want...it should do the trick...

EDIT if for each line sed 's/^.\{5\}//g' logfile


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon