Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

By default ack command prints the output in follwing way

ack --jsp '</div>'

a.jsp
5:</span></div>
10:</table></div>
b.jsp
3:</div><div>xyz
8:</div><a>

is there any way to output the result in following way ?

<filename>:<linenum>:<matchedtext>   

a.jsp:5:</div>
a.jsp:10:</div>
b.jsp:3:</div>
b.jsp:8:</div>

Though there is --output=expr to output match based on regex capture group I am not sure if there is any way to get the name of the file that has matched text along with the line number

ack --jsp -o -h --output=':$1:$2' '(</(div)>)'

:</div>:div
:</div>:div
:</div>:div
:</div>:div

if not possible with ack, is there any alternate way to do it ?

share|improve this question

Ok a quick scan through ack source I found following command line option to get required result

ack --jsp --nogroup -o '(</(div)>)'


a.jsp:5:</div>
a.jsp:10:</div>
b.jsp:3:</div>
b.jsp:8:</div>

or

ack --jsp --nogroup --output='$2' '(</(div)>)'


a.jsp:5:div
a.jsp:10:div
b.jsp:3:div
b.jsp:8:div
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .