Comparer deux chaine differentes

Résolu/Fermé
Flyzerd - 10 déc. 2015 à 22:44
Flyzerd Messages postés 15 Date d'inscription mardi 18 mars 2014 Statut Membre Dernière intervention 24 décembre 2016 - 11 déc. 2015 à 21:53
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..
A voir également:

1 réponse

dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
Modifié par dubcek le 11/12/2015 à 09:14
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
0
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
11 déc. 2015 à 16:34
ou
while read line
do
if [[ "$line" =~ ^bonjour:|^date:|^wow: ]];then
echo $line >> new_plop.txt
else
echo "haha" >> event2.txt
fi
done
0
Flyzerd Messages postés 15 Date d'inscription mardi 18 mars 2014 Statut Membre Dernière intervention 24 décembre 2016 1
11 déc. 2015 à 21:53
Merci beaucoup ! ça marche !
0