Comparer deux chaine differentes

Résolu
Bonjour,
Alors je vous explique :
J'ai un fichier plop.txt
qui contient :

bonjour:ca va bien
kata:klop
date:051 5410 0
truc: au hasard
wow: pas mal 04
bonjour:111
kata:dadz
date:222
truc: grtyy
wow: 333


et j'aimerais pouvoir faire cela :

>new_plop.txt
while read line
do
if [ "$line" = "^bonjour:.*" ];then
echo $line >> new_plop.txt
else if [ "$line" = "^date:.*" ];then
echo $line >> new_plop.txt
else if [ "$line" = "^wow:.*" ];then
echo $line >> new_plop.txt
else
echo "haha" >> event2.txt
fi
fi
fi
done < plop.txt


et que mon fichier new_plop.txt contient après cela :

bonjour:ca va bien
date:051 5410 0
wow: pas mal 04
bonjour:111
date:222
wow: 333


Merci pour votre aide ! à très bientôt j'espère..

1 réponse

  1. Contributeur
    hello
    while read line
    do
    if [[ "$line" =~ ^bonjour: ]];then
    echo $line >> new_plop.txt
    else if [[ "$line" =~ ^date: ]];then
    echo $line >> new_plop.txt
    else if [[ "$line" =~ ^wow: ]];then
    echo $line >> new_plop.txt
    else
    echo "haha" >> event2.txt
    fi
    fi
    fi
    done < plop.txt
    1. Contributeur
      ou
      while read line
      do
      if [[ "$line" =~ ^bonjour:|^date:|^wow: ]];then
      echo $line >> new_plop.txt
      else
      echo "haha" >> event2.txt
      fi
      done
    2. Merci beaucoup ! ça marche !