Pages

vendredi 16 mars 2012

find and change in text with grep and sed

given a text file ($file) containing:


1.0  1  user  /home/user/tahiti_la2_mrb0/la2_22530_elim_1fois
1.0  1  user  /home/user/tahiti_la2_mrb0/la2_22540_elim_1fois
1.0  1  user  /home/user/tahiti_sta_mrb0/sta_22460_elim_1fois
1.0  1  user  /home/user/tahiti_sta_mrb0/sta_22470_elim_1fois


if we want to change the 1.0 to 0.6 in any line which contains "la", and change 1.0 to 1.2 in any line which contains "st", we can do:


cat  $file  |  grep "_la"   | sed   's/1./0.6/'     >> $file"_0.61.2"
cat  $file  |  grep "_st"   | sed   's/1./1.2/'     >> $file"_0.61.2"



Aucun commentaire:

Enregistrer un commentaire