XML-Dateien finden, die keinen bestimmten Kommentar von der Shell enthalten
Ich möchte (awk / grep / sed) in einigen XML-Dateien (pom.xml-Datei) suchen und dabei einen Ordner überspringen. Darüber hinaus ist die erste Bedingung, dass sie das Tag @ enthalten müss<module>
. In diesen Fällen möchte ich diejenigen ausdrucken, die die unten angegebene Sequenz nicht genau enthalten (es handelt sich um automatisch generierten Code - Es hilft mir festzustellen, ob jemand diese Sequenz geändert hat):
<!--
| Start of user code (user defined modules)
|-->
<!--
| End of user code
|-->
Im hier stecken:
fileArray=($(find . -type f -not -path "./folder1/*" -not -path "*/folder2/*" -not -path "./folder3/*" -name "pom.xml" \
| xargs awk -v RS='^ Einige Tipps bitte?
---AKTUALISIEREN
#!/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 (letzte Konsolenausgabe)
:~/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]}'))
Einige Tipps bitte?
---AKTUALISIEREN
#!/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 (letzte Konsolenausgabe)
:~/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 (letzte Konsolenausgabe)
:~/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]}'))
Einige Tipps bitte?
---AKTUALISIEREN
#!/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 (letzte Konsolenausgabe)
:~/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 (letzte Konsolenausgabe)
:~/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]}'))
Einige Tipps bitte?
---AKTUALISIEREN
#!/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 (letzte Konsolenausgabe)
:~/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.