I know that I may have the C package #include <stdint.h> in the first 1-30 lines. I would like to add it to lines where no previously if the file contains the word LARGE_INTEGER by GNU tools. Substitute [0,1] matchesI thought first about replacing [0,1] matches always as follows but now I think the extra substitution is unnecessary so should be avoided:gsed -i '1-30s/^(#include <stdint.h>\n)?/#include <stdint.h>\n/'I propose to reject this. Extra ggrep approach to say no matchI think this may be a good solution because it first looks the conditions and then substitutes if necessary.This thread suggests to add an extra grep so code where the while loop structure is from here while read -d '' -r filepath; do                                \    [ $(ggrep -l LARGE_INTEGER $filepath) ] &&            \    [ $(ggrep -L #include <stdint.h> $filepath) ]          \    | gsed -i '1s/^/#include <stdint.h>\n/' $filepathdonewhich however givestest.sh: line 5: stdint.h: No such file or directoryand does add the package to lines without #include <stdint.h> too which is wrong. How can you combine two conditional statements for SED efficiently?
To sed if with and without conditions correct
bash;sed;grep;gnu
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 -n '/:0$/ { s/:0$//; p; }')The script assumes GNU sed (for -i).In detail:fgrep -lw LARGE_INTEGER * lists the files in the current directory that contain the word LARGE_INTEGERegrep -c '#include +<stdint\.h>' counts the occurrences of #include <stdint.h> through the files found by fgrep abovesed -n '/:0$/ { s/:0$//; p; }' selects the files with 0 matches and keeps only the filenamessed -i -e '1i\' -e '#include <stdint.h>' adds a first line #include <stdint.h> to the files found above.