Tag Info

New answers tagged

2

I'm not sure I decrypted your prose correctly. The script below adds #include <stdint.h> to files in the current directory that (1) contain the word LARGE_INTEGER, and (2) don't already include <stdint.h>: sed -i -e '1i\' -e '#include <stdint.h>' $( egrep -c '#include +<stdint\.h>' $( fgrep -lw LARGE_INTEGER * ) | \ sed ...


3

I'd use1 find with two -exec actions e.g.: find . -type f -exec grep -qF SOME_STRING {} \; -exec sed 'COMMAND' {} \; The second command will run only if the first one evaluates to true i.e. exit code 0 so sed will process the file in question only if the file contains SOME_STRING. It's easy to see how it works: find . -type f -exec grep -qF SOME_STRING {} ...


1

Just pipe the output of gfind to xargs: gfind /tmp/ -type f \( -name "*.h" -o -name "*.cpp" \) -exec ggrep -l "LARGE_INTEGER" {} + | xargs sed -i '1s/^/#include <stdint.h>\n/' Notice that I've removed the -P option from ggrep, since you're matching a fixed string. However this solution doesn't deal well with filenames containing newlines; a safer ...



Top 50 recent answers are included