Creating files with Touch

0

I have to create, from each file that pass me by parameter, a file with each line of the form filename . numeroNLaLinea . The code that I thought is the following:

#!/bin/bash

for file in $@
do
    i=0
    if [[ -s $file ]]
    then
        echo $file | while read line
        do
            (( i++ ))
            echo $line >> /var/log/FicherosDeTexto/$file.$i
        done
    else
        touch /var/log/FicherosDeTexto/$file.$i
    fi
done

The fact is that when creating each of the files I get the following errors:

touch: no se puede efectuar 'touch' sobre «/var/log/FicherosDeTexto/FicherosAyuda/Vacio.0»: No existe el fichero o el directorio

./act1.sh: línea 11: /var/log/FicherosDeTexto/FicherosAyuda/Archivo3lineas.1: No existe el fichero o el directorio
    
asked by Carlos Martel Lamas 08.11.2016 в 21:23
source

1 answer

0

That error is caused by the non-existence of part of the route; if the file to be created is

/home/trauma/prueba/ruta2/hola.txt

and the /home/trauma/prueba/ruta2 directory does not exist, it causes that error.

Make sure the file names do not include the character '/', and try putting mkdir -p RUTAS/A/CREAR before creating the files.

    
answered by 08.11.2016 / 21:47
source