0
votes

Comment obtenir une ligne particulière d'un tableau à chaîne

/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

1 commentaires

Comment imprimez-vous / stockez-vous le tableau? Dans quelle coquille êtes-vous sur?


3 Réponses :


0
votes

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


0 commentaires

1
votes

Voir l'exemple ci-dessous: XXX PRE>

Sortie: P>

..foo/..


0 commentaires

0
votes

GREP - Les lignes d'impression correspondant à un motif.

Par exemple: < / p> xxx

aussi grep pourrait également être utilisé dans le script: xxx

sortie: xxx


1 commentaires

Pourquoi le . * ? Vous pouvez les supprimer. Sans -X option à Grep, il ne correspond pas à l'ensemble de la ligne exacte, seule une partie de celui-ci.