Convertir filas columnas en columnas
Partiendo del fichero
si hacemos
cat file5_new.txt | tr '\n' ' ' | awk '{$1=$1}1' FS=" " OFS="\t" > file5_restore.txt
obtenemos
Partiendo del fichero
si hacemos
cat file5_new.txt | tr '\n' ' ' | awk '{$1=$1}1' FS=" " OFS="\t" > file5_restore.txt
obtenemos
Para renombrar un fichero: #!/bin/bash # Renombra el fichero según las etiquetas mp3, de la forma: NºCanción-Título TITLE="`id3info "$1" | grep ‘^=== TIT2’ | sed -e ‘s/.*: //g’`" #ARTIST="`id3info "$1" | grep ‘^=== TPE1’ | sed -e ‘s/.*: //g’`" #ALBUM="`id3info "$1" | grep ‘^=== TALB’ | sed -e ‘s/.*: //g’`" #YEAR="`id3info "$1" | grep ‘^===…
#!/bin/bash echo "Cleaning logs over $1 days old" find /log_dir -ctime "$1" -name ‘*log’ -exec rm {} \;
Comandos útiles !! Repite el último comando. !n Repite el comando número n (de history). !$ Último argumento del comando anterior. !:n Argumento número n del comando anterior. Combinaciones de teclas Combinación de teclas Acción Ctrl + A Ir al comienzo de la línea Ctrl+E Ir al final de la línea Ctrl+F Ir al siguiente…
Se tiene el fichero: haciendo awk ‘{for(i=1;i<=NF;i++){print $i}}’ file5.txt > file5_new.txt se tiene:
Tenemos el fichero Si se quiere la suma de la columna col3: awk ‘BEGIN{FS="\t";count=0}{if(NR>1){count+=$3}}END{print count}’ file6.txt se obtiene: 171
# Devuelve un número aleatorio entre 1 y 100 echo $[ ( $RANDOM % 100 ) + 1 ]