Answer the question
In order to leave comments, you need to log in
How to change grep output?
Can't figure out grep output. You need to find files that contain a specific string, but make the output in the format Full path to the file, name and size.
at the moment I grep -r "something" /path
conclude: path/to/file:string
I'm trying to make Path: Path/to/file Name: Name Size: SizeKB
In general, I'm looking for an analogue of -printf in find, there it is done by adding -printf "Path: %p Name: %f Size: %kKB\n"
thanks in advance))
Answer the question
In order to leave comments, you need to log in
grep doesn't have these options, so you need to process grep's output with something else.
A simple example is here:
grep -r -l "something" | xargs stat --format="Name: %n Size: %B"
while read; do
MYPATH="${REPLY%/*}"
MYNAME="${REPLY##*/}"
SIZE="$(stat --format='%s' ${REPLY})"
&& MYPATH=""
echo "Path: ${MYPATH}/ Name: ${NAME} Size: ${SIZE}"
done<<<$(grep -r -l "alias")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question