Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm running an application that is outputing lines, piping to GREP to select only specific lines, but want to remove the first X characters which are worthless.

Specifically:

varnishlog | grep Hash

Produces for example

   34 Hash         c /address
   41 Hash         c /addresss?xml=1&

I want the last part after the "c" in order to record these in a file.

Which command do I pipe to.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

awk works, but I think cut is simpler for this task, e.g.

$ varnishlog | grep Hash | cut -b 23-

-b specifies bytes, and 23- says keep the 23rd byte to the end of the line.

You could also use -c, which is characters instead of bytes (in this case characters == bytes)

share|improve this answer

I did some research and came up with the following using AWK:

$ varnishlog | grep Hash | awk {'print substr($0,23)}'

This filters out the first 23 characters and leaves the part that I want.

If anyone has a better answer please post.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.