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] matches
I 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 match
I 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/' "$filepath"
done
which however gives
test.sh: line 5: stdint.h: No such file or directory
and does add the package to lines without #include <stdint.h>
too which is wrong.
How can you combine two conditional statements for SED efficiently?
find
. See my updated post for a generic example but really, you should make an effort and try to understand how it works (the man page is your best friend). Believe me, it will pay off in the long run. Regards. – don_crissti Jun 30 '15 at 19:04find -qF -size -15k ... {} \;
. – Léo Léopold Hertz 준영 Jun 30 '15 at 19:36