Question

if you do grep -n, the output format is like this,

filename:line:

Is it possible for me to tell grep to replace the first : with + so that I can copy paste the string to vim to go to that line?

What I want is this,

filename +line:

Any idea how to achieve this?

Était-ce utile?

La solution

Pipe the output to sed.

grep -n needle haystack1 haystack2  | sed 's/:/ +/'

If you then want to strip off the part after, so that it is even easier to paste to vim, you can pipe it to awk.

grep -n needle haystack1 haystack2  | sed 's/:/ +/' | awk -F':' '{print $1}'
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top