views:

1469

answers:

3

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.

Thanks in advance stackoverflow geniuses!

-- LES

A: 

cut' WORKS!

tail -f logfile | grep org.springframework | cut -c 900-

would remove the first 900 characters

'cut' uses 900- to show the 900th character to the end of the line

however

when i pipe all of this through grep i don't get anything :(

LES2
"cut -c 1-900" will not "remove the first 900 characters" -- it will leave only the first 900 characters. If you want to remove the first 900 chars, use "cut -c 901-"
iammichael
also it's first 900 characters on each line, per @iammichael's answer
Blair Conrad
thanks ... i was editing my comment as you guys typed this :)
LES2
+6  A: 

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-
iammichael
do you have any idea of why the pipe doesn't work? when i run essentially that command, 'cut' doesn't print the results to stdout ... if i just run 'tail -f logfile | cut -c 5-' i can see the results ... the problem must be with grepi'm using cygwin FYIthanks
LES2
what does happen if you do not add the last pipe and cut ? basically, if you remove the last part of the line ?
LB
it "tails" the logfile, filtering it with grep (i.e., all of the lines with "org.springframework" in them are printed to stdout)when i add the pipe to 'cut' ... it hangsHOWEVER, if i eliminate 'grep' the 'cut' works properly ... i'm thinking something's wrong with how i'm using grep ... could be a cygwin thing too
LES2
oh i see...why do you use tail ? just do grep org.springframework logfile | cut -c 5-but i think sed is nicer :-)
LB
because the '-f' arg to 'tail' causes tail to continuously read the file ... it allows me to view updates to the logfile as they are written
LES2
+3  A: 
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

LB