When launching a find -exec
I get a list of results, separated by colons. Is there a way to turn those colons into some kind of "columns" separators (preferably a list of spaces)?
Turn:
Prompt> find ./ -name "*.*" -exec grep "namespace" {} /dev/null \;
./Alarm/AddedHandler.cs:namespace Alarm
./Alarm/DeletedHandler.cs:namespace Alarm
./Alarm/UpdatedHandler.cs:namespace Alarm
./Connections/AddedHandler.cs:namespace Connections
./Connections/DeletedHandler.cs:namespace Connections
./Connections/UpdatedHandler.cs:namespace Connections
./Robot.Api/AddedHandler.cs:namespace Robot
./Robot.Api/DeletedHandler.cs:namespace Robot
./Robot.Api/UpdatedHandler.cs:namespace Robot
... into:
Prompt> find ./ -name "*.*" -exec grep "namespace" {} /dev/null \; | <turn_colon_into_list_of_spaces>
./Alarm/AddedHandler.cs : namespace Alarm
./Alarm/DeletedHandler.cs : namespace Alarm
./Alarm/UpdatedHandler.cs : namespace Alarm
./Connections/AddedHandler.cs : namespace Connections
./Connections/DeletedHandler.cs : namespace Connections
./Connections/UpdatedHandler.cs : namespace Connections
./Robot.Api/AddedHandler.cs : namespace Robot
./Robot.Api/DeletedHandler.cs : namespace Robot
./Robot.Api/UpdatedHandler.cs : namespace Robot
(I don't care whether or not the colons are still present.)
CodePudding user response:
You can pipe the output to column
:
find ... | column -ts:
CodePudding user response:
This find sed
should work for you:
find . -type f -exec grep -H "namespace" {} | sed 's/:/\t\t\t/'
Here:
- Using
-H
option ingrep
to get filenames in output - Using
find
execution - Using
sed
to replace only first:
with 3 tabs