0

Hi,

I want to know just the name of the files that contains a given pattern. Then I would open the files in vi and replace the pattern. But using

grep -n '&&&' *

gives all the occurrence of the pattern which is not very helpful.

How do I view only the names?

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by gerard4143
0

This is not very relevant here. Because the same functionality should be agnostic to the pattern and file content. Still if you *insist* I can give you the file and pattern:

file
abcdefg&&&hijklmonp&&&qrs&&&tuv&&&wx&&&yz

pattern
&&&

replace pattern
----

so
abcdefg&&&hijklmonp&&&qrs&&&tuv&&&wx&&&yz

becomes
abcdefg---hijklmonp---qrs---tuv---wx---yz

0

This in from the manpages

1. How can I list just the names of matching files?

grep -l 'main' *.c

lists the names of all C files in the current directory whose
contents mention `main'.

So this should open each one in vi
vi grep -l 'main' *.c

Actually on my system I found this works.

vim $(grep -l 'main' *.c)

Edited by gerard4143: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.