Monday, July 01, 2013
[linux] llamando sed desde un script de bash
truco: usar comillas dobles, no la simple! si no no funciona.
let counter=1;
let thenewid=1;
for line in $(cat ./old_ids.txt); do
(( thenewid = $(head -$counter ./new_ids.txt | tail -1) ))
let counter+=1;
echo "$counter: -> $line will be $thenewid";
for lefichier in $(cat ./filetochange.txt); do
echo "sed 's/$line/$thenewid/g' ./$lefichier > ./foo.txt";
sed "s/$line /$thenewid /g" ./$lefichier > ./foo.txt;
# diff $lefichier ./foo.txt
# echo "cp ./foo.txt $lefichier"
cp ./foo.txt $lefichier;
done;
done;
[linux] comparar dos listas de numeros en dos archivos distintos
#! /bin/bash
# grep -v Desc deldirac.txt > tmp.txt
# # awk 'BEGIN {FS=" "} / / {print $1,$2}' tmp.txt
# awk 'BEGIN {FS=" "} / / {print $2}' tmp.txt > names_ids.txt
# awk 'BEGIN {FS=" "} / / {print $1}' tmp.txt > new_ids.txt
# cat names_ids.txt | xargs -I{} grep -l {} */*.dat */*.descr | sort | uniq > filetochange.txt
# cat names_ids.txt | xargs -I{} grep -wu -m 1 {} Descr/fich_visu_param.dat | cut -b 1-3 >> old_ids.txt
# cat old_ids.txt |
let counter=1;
let thenewid=1;
for line in $(cat ./old_ids.txt); do
(( thenewid = $(head -$counter ./new_ids.txt | tail -1) ))
let counter+=1;
echo "$counter: -> $line will be $thenewid";
done;