
Error con sed...
Publicado por Carlos (5 intervenciones) el 16/08/2021 08:56:34
Hola a ver si podéis orientarme tengo un fichero de texto con este formato
15/08/2021 17:00:01 texto aleatorio
15/08/2021 17:22:01 texto aleatorio
15/08/2021 17:36:01 texto aleatorio
15/08/2021 18:01:01 texto aleatorio
15/08/2021 18:06:01 texto aleatorio
15/08/2021 18:26:01 texto aleatorio
15/08/2021 18:48:01 texto aleatorio
15/08/2021 18:54:01 texto aleatorio
15/08/2021 18:54:01 texto aleatorio
16/08/2021 17:00:01 texto aleatorio
16/08/2021 17:22:01 texto aleatorio
16/08/2021 17:36:01 texto aleatorio
Lo que quiero es que si hoy es día 16, me borré las líneas del día anterior (15)
Tengo este script en sh
Si ejecutó en Shell me funciona
Pero si lo ejecutó como sh script.sh. no me da error, me crear un file1.txt no legible.
¿Alguna sugerencia?
¿Algo para que me lo dejé procesado en el mismo fichero en vez de file1.txt?
Gracias
15/08/2021 17:00:01 texto aleatorio
15/08/2021 17:22:01 texto aleatorio
15/08/2021 17:36:01 texto aleatorio
15/08/2021 18:01:01 texto aleatorio
15/08/2021 18:06:01 texto aleatorio
15/08/2021 18:26:01 texto aleatorio
15/08/2021 18:48:01 texto aleatorio
15/08/2021 18:54:01 texto aleatorio
15/08/2021 18:54:01 texto aleatorio
16/08/2021 17:00:01 texto aleatorio
16/08/2021 17:22:01 texto aleatorio
16/08/2021 17:36:01 texto aleatorio
Lo que quiero es que si hoy es día 16, me borré las líneas del día anterior (15)
Tengo este script en sh
1
2
3
4
5
#!/bin/sh
one=1
dataset_date=`date`
today=`date -d "$dataset_date - $one days" +%d`
sed "/^$today/ d" file.txt > file1.txt
Si ejecutó en Shell me funciona
1
2
3
4
one=1
dataset_date=`date`
today=`date -d "$dataset_date - $one days" +%d`
sed "/^$today/ d" file.txt > file1.txt
Pero si lo ejecutó como sh script.sh. no me da error, me crear un file1.txt no legible.
¿Alguna sugerencia?
¿Algo para que me lo dejé procesado en el mismo fichero en vez de file1.txt?
Gracias
- File.zip(14,2 KB)
Valora esta pregunta


0