Archive for the 'Scripting' Category

Master piece, and a song.

Saturday, February 20th, 2010

Browsing the internet I found this then I’d say “hey, if there is a flowchart there should be a code” then I’d found out that the flowchart was wrong, nevertheless I’ve written the bash code for the full Beattles – Hey Jude song.
#!/bin/bash
for i in $(seq 1 1 4)
do
echo " "
echo -n "Hey Jude don't "
if [ $i == 1 ] || [ $i == 4 ]; then
echo "make it bad"
echo "Take a sad song and make it better"
fi
if [ $i == 2 ]; then
echo "be afraid"
echo "You were made to go out and get her"
fi
if [ $i == 3 ]; then
echo "let me down"
echo "You have found her, now go and get her"
fi
if [ $i == 1 ] || [ $i == 3 ] ; then
echo "Remember to let her into your heart"
else
echo "The minute you let her under your skin"
fi
echo -n "Then you "
if [ $i == 1 ] || [ $i == 3 ] ; then
echo -n "can start "
else
echo -n "begin "
fi
echo "to make it better"
if [ $i == 2 ]; then
echo " "
echo "And any time you feel the pain, Hey Jude, refrain"
echo "Don't carry the world upon your shoulders"
echo "For well you know that it's a fool who plays it cool"
echo "By making his world a little colder"
fi

if [ $i == 3 ]; then
echo " "
echo "So let it out and let it in"
echo "Hey Jude begin"
echo "You're waiting for someone to perform with"
echo "And don't you know that it's just you"
echo "Hey Jude you'll do"
echo "The movement you need is on your shoulder"
fi
done

Comparando linea por linea dos archivos en bash

Thursday, February 11th, 2010

Frecuentemente me veo en la necesidad de comparar archivos no sorteados linea por linea sobre todo para parceo de configuraciones y cada que lo requiero tengo que buscar de nuevo la info en internet, asi que para futuras referencias pongo aqui el metodo mas sencillo que me he encontrado, basicamente se guarda un archivo en en descriptor 7, se abre linea por linea y se va comparando toda la linea abierta contra todas las lineas de otro archivo abierto en el momento, quienes hayan intentado hacerlo me entenderan ya que en bash si abres dos archivos a la vez cierra el primero para permitirte trabajar con el segundo.


aduarte@aduarte:/$ cat a.txt
b
c
d

aduarte@aduarte:/$ cat b.txt
1
2
3

aduarte@aduarte:/$ cat opentowfiles.sh
#!/bin/bash
exec 7
cat <&7 | while read LA
do
cat b.txt | while read LB
do
echo $LA $LB
done
done

aduarte@aduarte:/$ ./opentowfiles.sh
b 1
b 2
b 3
c 1
c 2
c 3
d 1
d 2
d 3