|
1 |
echo " este es un ejemplo" | sed 's/ //g' |
dara como resultado :
|
1 |
esteesunejemplo |
#!/bin/bash
echo "TEXTO ORIGINAL"
echo "--------------"
while read linea; do
echo $linea
done < texto.txt
echo "TEXTO CORREGIDO"
echo "---------------"
while read linea; do
text1=echo $linea | cut -d"|" -f1
text1="${text1#"${text1%%[![:space:]]*}"}"
text1="${text1%"${text1##*[![:space:]]}"}"
text2=echo $linea | cut -d"|" -f2
text2="${text2#"${text2%%[![:space:]]*}"}"
text2="${text2%"${text2##*[![:space:]]}"}"
text3=echo $linea | cut -d"|" -f3
text3="${text3#"${text3%%[![:space:]]*}"}"
text3="${text3%"${text3##*[![:space:]]}"}"
text4=echo $linea | cut -d"|" -f4
text4="${text4#"${text4%%[![:space:]]*}"}"
text4="${text4%"${text4##*[![:space:]]}"}"
text5=echo $linea | cut -d"|" -f5
text5="${text5#"${text5%%[![:space:]]*}"}"
text5="${text5%"${text5##*[![:space:]]}"}"
echo "$text1|$text2|$text3|$text4|$text5"
done < texto.txt
Ejemplo de su ejecución. Para este caso se trabajara sobre un archivo «texto.txt». El script leera linea por linea el archivo y procedera a cortar con el comandi «cut» por medio del delimitador «|» . Posterior a esto procedera a eliminar los espacios delante y atras de la variables.
bash prueba.sh
TEXTO ORIGINAL
--------------
1534 55789 |723092 | 12203|31/05/2020 15:28:42 |05/01/2021 12:10:44
1264 56589 |173094 | 12203|31/05/2020 15:28:42 |06/01/2021 14:10:44
1237 56769 |127097 | 12203|31/05/2020 15:28:42 |07/01/2021 18:10:44
TEXTO CORREGIDO
---------------
1534 55789|723092|12203|31/05/2020 15:28:42|05/01/2021 12:10:44
1264 56589|173094|12203|31/05/2020 15:28:42|06/01/2021 14:10:44
1237 56769|127097|12203|31/05/2020 15:28:42|07/01/2021 18:10:44