/server/fmw/idm_111/opatch2019-01-25_08-20-55AM_1.log /server/fmw/oamwebgate11g/opatch2019-01-25_08-20-57AM_1.log /server/fmw/ohs_111/opatch2019-01-25_08-20-59AM_1.log /server/fmw/oracle_common/opatch2019-01-25_08-21-01AM_1.log above is the content of a string array in a shell, want to get the line which has ohs_111
3 Réponses :
Comme il est expliqué dans Comment Vérifiez si une chaîne contient une sous-chaîne dans Bash par exemple:
#!/bin/bash array=("/server/fmw/idm_111/opatch2019-01-25_08-20-55AM_1.log" "/server/fmw/oamwebgate11g/opatch2019-01-25_08-20-57AM_1.log" "/server/fmw/ohs_111/opatch2019-01-25_08-20-59AM_1.log" "/server/fmw/oracle_common/opatch2019-01-25_08-21-01AM_1.log" ) for i in ${!array[*]} do if [[ "${array[$i]}" == *"ohs_111"* ]] then echo "${array[$i]}" fi done
Voir l'exemple ci-dessous: Sortie: P> ..foo/..
GREP - Les lignes d'impression correspondant à un motif.
Par exemple: < / p> aussi grep pourrait également être utilisé dans le script: p> sortie: p>
Pourquoi le . * Code>? Vous pouvez les supprimer. Sans
-X code> option à Grep, il ne correspond pas à l'ensemble de la ligne exacte, seule une partie de celui-ci.
Comment imprimez-vous / stockez-vous le tableau? Dans quelle coquille êtes-vous sur?