Grep pipe with sed

This is my bash command

grep -rl "System.out.print" Project1/ | 
    xargs -I{} grep -H -n "System.out.print" {} |
    cut -f-2 -d: |
    sed "s/\(.*\):\(.*\)/filename is \1 and line number is \2/

What I'm trying to do here, I'm trying to iterate through subfolders and check which files contain "System.out.print" (using grep) using a second grep, trying to get the file names and line numbers using the sed command, I show them to the console. from here I want to remove "System.out.print" using "XXXXX", how can I pass the sed command to the command? Pls help me thanxx

+3
source share
2 answers

GNU sed has the ability to modify files in place:

find Project1/ -type f | xargs sed -i 's/System\.out\.print/XXXXX/g'

Btw, your script can be written as:

grep -rsn 'root' /etc/ |
    awk -F: '{ print "filename is", $1, "and line number is", $2 }'
+10
source

, , find -exec. _, , , .., ( ) - /dev,/sys,/proc . , xargs; .

grep -HriIl --exclude-dir=dev --exclude-dir=proc --exclude-dir=sys search_text / | xargs sed -i 's/search_text/replace_text/g'
0

Source: https://habr.com/ru/post/1781804/


All Articles