Reputation: 325
I'm trying to write a script that Highlights TODO comments in a directory or file. The issue that I keep running into is that the I'm trying to have the following output format
TODO: Here is what i need to do -> example-file.txt:linenumber
The parser won't grab the comment because the ':' after the TODO.
#!/bin/bash
echo "TODO highlighter..."
grep -Hnr --color 'TODO' $* | awk -F: '{print $'${@:3}'" -> "$1 ":" $2}'
here is the file ive been using to test (todo-example.java):
//TODO: Bobo region Description
//todo this is good but needs new name
//TODO- John fix
and this is the output:
//output
todo-example.java:4://TODO: Bobo region Descriptiontodo-example.java:4
todo-example.java:29: //TODO- John fix todo-example.java:29
//desired output
//TODO: Bobo region Description -> todo-example.java:4
//TODO- John fix -> todo-example.java:29
I have tried changing the arguments but i cant seem to get the desired results of $3 to $N. Thanks.
Upvotes: 0
Views: 39
Reputation: 6333
you just need the following line in your script:
awk '/TODO/ { print FILENAME": "NR" -> "$0 }' "$@"
to highlight TODO
, you can trivially reuse your grep command:
awk '/TODO/ { print FILENAME": "NR" -> "$0 }' "$@" | grep --color 'TODO'
Upvotes: 3