Encontre arquivos XML que não contenham um comentário específico do shell
Quero pesquisar (awk / grep / sed) em alguns arquivos XML (arquivo pom.xml) pulando alguma pasta. Além disso, a primeira condição é que eles devem conter a tag<module>
. Nesses casos, quero imprimir aqueles que não contêm exatamente a sequência abaixo (é um código gerado automaticamente - isso me ajudará a detectar se alguém modificou essa sequência):
<!--
| Start of user code (user defined modules)
|-->
<!--
| End of user code
|-->
Estou preso aqui:
fileArray=($(find . -type f -not -path "./folder1/*" -not -path "*/folder2/*" -not -path "./folder3/*" -name "pom.xml" \
| xargs awk -v RS='^Algumas dicas, por favor?
---ATUALIZAR:
#!/bin/sh
###########################################################
# Checks for "user code" <modules> defined in pom files.
###########################################################
function check()
{
# http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
OLDIFS=$IFS
IFS=---- UPDATE (última saída do console)
:~/temp> bash script.sh
awk: cmd. line:1: fatal: cannot open file `{}' for reading (No such file or directory)
ERROR:Found user code modules (file:line:occurrence): ./test_folder/test4/pom.xml ./tes t_folder/test1/pom.xml ./test_folder/test2/pom.xml ./test_folder/test3/pom.xml
SUMMARY:Found 1 pom.xml file(s) containing user code modules.
'match($0,/\<module>[^\n]+/,a){print a[0]}'))
Algumas dicas, por favor?
---ATUALIZAR:
#!/bin/sh
###########################################################
# Checks for "user code" <modules> defined in pom files.
###########################################################
function check()
{
# http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
OLDIFS=$IFS
IFS=$'\n'
# Read all pom files into an array
# - Search for user code modules: It searches for the tag <module> into the pom files and in case they contain modules,
#checks if the autogenerated section has been modified. Reading text secuence from foo.txt file
#
# - Exclude model folder as the codegen poms therein require such a repository
fileArray=($(find . -type f -not -path "./folder1/*" -not -path "*/folder2/*" -not -path "./folder3/*" -name "pom.xml" \
| xargs `awk -v RS='^$' 'NR==FNR{str=$0;next} /<module>/ && !index($0,str){print FILENAME}' sequence {} +`))
IFS=$OLDIFS
# get length of an array
numberOfFiles=${#fileArray[@]}
# read all filenames
for (( i=0; i<${numberOfFiles}; i++ ));
do
echo "ERROR:Found user code modules (file:line:occurrence): ${fileArray[$i]}"
done
if [ "$numberOfFiles" != "0" ]; then
echo "SUMMARY:Found $numberOfFiles pom.xml file(s) containing user code modules."
exit 1
fi
}
check
---- UPDATE (última saída do console)
:~/temp> bash script.sh
awk: cmd. line:1: fatal: cannot open file `{}' for reading (No such file or directory)
ERROR:Found user code modules (file:line:occurrence): ./test_folder/test4/pom.xml ./tes t_folder/test1/pom.xml ./test_folder/test2/pom.xml ./test_folder/test3/pom.xml
SUMMARY:Found 1 pom.xml file(s) containing user code modules.
\n'
# Read all pom files into an array
# - Search for user code modules: It searches for the tag <module> into the pom files and in case they contain modules,
#checks if the autogenerated section has been modified. Reading text secuence from foo.txt file
#
# - Exclude model folder as the codegen poms therein require such a repository
fileArray=($(find . -type f -not -path "./folder1/*" -not -path "*/folder2/*" -not -path "./folder3/*" -name "pom.xml" \
| xargs `awk -v RS='^---- UPDATE (última saída do console)
:~/temp> bash script.sh
awk: cmd. line:1: fatal: cannot open file `{}' for reading (No such file or directory)
ERROR:Found user code modules (file:line:occurrence): ./test_folder/test4/pom.xml ./tes t_folder/test1/pom.xml ./test_folder/test2/pom.xml ./test_folder/test3/pom.xml
SUMMARY:Found 1 pom.xml file(s) containing user code modules.
'match($0,/\<module>[^\n]+/,a){print a[0]}'))
Algumas dicas, por favor?
---ATUALIZAR:
#!/bin/sh
###########################################################
# Checks for "user code" <modules> defined in pom files.
###########################################################
function check()
{
# http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
OLDIFS=$IFS
IFS=$'\n'
# Read all pom files into an array
# - Search for user code modules: It searches for the tag <module> into the pom files and in case they contain modules,
#checks if the autogenerated section has been modified. Reading text secuence from foo.txt file
#
# - Exclude model folder as the codegen poms therein require such a repository
fileArray=($(find . -type f -not -path "./folder1/*" -not -path "*/folder2/*" -not -path "./folder3/*" -name "pom.xml" \
| xargs `awk -v RS='^$' 'NR==FNR{str=$0;next} /<module>/ && !index($0,str){print FILENAME}' sequence {} +`))
IFS=$OLDIFS
# get length of an array
numberOfFiles=${#fileArray[@]}
# read all filenames
for (( i=0; i<${numberOfFiles}; i++ ));
do
echo "ERROR:Found user code modules (file:line:occurrence): ${fileArray[$i]}"
done
if [ "$numberOfFiles" != "0" ]; then
echo "SUMMARY:Found $numberOfFiles pom.xml file(s) containing user code modules."
exit 1
fi
}
check
---- UPDATE (última saída do console)
:~/temp> bash script.sh
awk: cmd. line:1: fatal: cannot open file `{}' for reading (No such file or directory)
ERROR:Found user code modules (file:line:occurrence): ./test_folder/test4/pom.xml ./tes t_folder/test1/pom.xml ./test_folder/test2/pom.xml ./test_folder/test3/pom.xml
SUMMARY:Found 1 pom.xml file(s) containing user code modules.
'NR==FNR{str=$0;next} /<module>/ && !index($0,str){print FILENAME}' sequence {} +`))
IFS=$OLDIFS
# get length of an array
numberOfFiles=${#fileArray[@]}
# read all filenames
for (( i=0; i<${numberOfFiles}; i++ ));
do
echo "ERROR:Found user code modules (file:line:occurrence): ${fileArray[$i]}"
done
if [ "$numberOfFiles" != "0" ]; then
echo "SUMMARY:Found $numberOfFiles pom.xml file(s) containing user code modules."
exit 1
fi
}
check
---- UPDATE (última saída do console)
:~/temp> bash script.sh
awk: cmd. line:1: fatal: cannot open file `{}' for reading (No such file or directory)
ERROR:Found user code modules (file:line:occurrence): ./test_folder/test4/pom.xml ./tes t_folder/test1/pom.xml ./test_folder/test2/pom.xml ./test_folder/test3/pom.xml
SUMMARY:Found 1 pom.xml file(s) containing user code modules.
'match($0,/\<module>[^\n]+/,a){print a[0]}'))
Algumas dicas, por favor?
---ATUALIZAR:
#!/bin/sh
###########################################################
# Checks for "user code" <modules> defined in pom files.
###########################################################
function check()
{
# http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
OLDIFS=$IFS
IFS=$'\n'
# Read all pom files into an array
# - Search for user code modules: It searches for the tag <module> into the pom files and in case they contain modules,
#checks if the autogenerated section has been modified. Reading text secuence from foo.txt file
#
# - Exclude model folder as the codegen poms therein require such a repository
fileArray=($(find . -type f -not -path "./folder1/*" -not -path "*/folder2/*" -not -path "./folder3/*" -name "pom.xml" \
| xargs `awk -v RS='^$' 'NR==FNR{str=$0;next} /<module>/ && !index($0,str){print FILENAME}' sequence {} +`))
IFS=$OLDIFS
# get length of an array
numberOfFiles=${#fileArray[@]}
# read all filenames
for (( i=0; i<${numberOfFiles}; i++ ));
do
echo "ERROR:Found user code modules (file:line:occurrence): ${fileArray[$i]}"
done
if [ "$numberOfFiles" != "0" ]; then
echo "SUMMARY:Found $numberOfFiles pom.xml file(s) containing user code modules."
exit 1
fi
}
check
---- UPDATE (última saída do console)
:~/temp> bash script.sh
awk: cmd. line:1: fatal: cannot open file `{}' for reading (No such file or directory)
ERROR:Found user code modules (file:line:occurrence): ./test_folder/test4/pom.xml ./tes t_folder/test1/pom.xml ./test_folder/test2/pom.xml ./test_folder/test3/pom.xml
SUMMARY:Found 1 pom.xml file(s) containing user code modules.