Resumen:
Imprimir de forma inversa cada línea de archivo.txt:
while read in; do
echo "$in"| rev ;
done < archivo.txt
El comando rev imprime el texto de forma inversa. Hola lo imprimirá aloH
echo "Hola mundo" | rev
odnum aloH
En ocasiones es necesario ejecutar un comando por cada línea de un archivo. En este ejemplo se imprimirá la misma línea de forma inversa, con el objetivo de poder manipular el string de forma más fácil
El archivo síguete archivo tiene caracteres especiales (—- More^M —-^[[42D ^[[42D ) lo cual dificulta la manipulación
. Lo que se pretende es imprimir en orden inverso cada linea y usado “cut” eliminar los caracteres especiales.
tcp VPN: public --> public 10.90.145.11:52437 --> 172.24.4.6:31943
icmp VPN: public --> public 172.24.4.6:41044 --> 172.24.0.5:2048
icmp VPN: public --> public 10.254.253.18:13482 --> 172.24.6.162:2048
icmp VPN: public --> public 172.24.4.6:63572 --> 172.24.0.1:2048
https VPN: public --> public 172.24.1.149:46169 --> 172.24.1.135:443
icmp VPN: public --> public 10.90.145.13:31742 --> 172.24.6.66:2048
tcp VPN: public --> public 172.24.7.37:50544 --> 172.24.7.118:8088
udp VPN: public --> public 172.24.8.214:13456 --> 192.141.244.6:38812
tcp VPN: public --> public 172.24.7.37:46394 --> 172.24.7.118:8088
tcp VPN: public --> public 192.168.202.11:44434 --> 172.24.6.162:7081
tcp VPN: public --> public 10.90.145.13:46860 --> 172.24.4.6:31943
tcp VPN: public --> public 172.24.8.20:36267 --> 172.24.8.136:8084
http VPN: public --> public 172.24.6.161:28230 --> 10.254.253.23:80
tcp VPN: public --> public 172.24.3.14:55335 --> 172.24.4.34:8088
icmp VPN: public --> public 10.90.145.13:31686 --> 172.24.6.164:2048
tcp VPN: public --> public 172.24.3.14:49684 --> 172.24.4.28:8088
tcp VPN: public --> public 10.254.253.25:46428 --> 172.24.6.162:7181
tcp VPN: public --> public 192.168.206.11:57416 --> 172.24.6.162:7081
tcp VPN: public --> public 192.168.202.11:44420 --> 172.24.6.162:7081
tcp VPN: public --> public 192.168.202.11:44354 --> 172.24.6.162:7081
icmp VPN: public --> public 10.90.145.13:31780 --> 172.24.2.137:2048
tcp VPN: public --> public 10.254.253.25:42030 --> 172.24.6.162:7081
tcp VPN: public --> public 192.168.202.11:44406 --> 172.24.6.162:7081
---- More^M ----^[[42D ^[[42D tcp VPN: public --> public 10.8.73.91:40168 --> 172.24.6.23:16570
tcp VPN: public --> public 10.8.73.116:35450 --> 172.24.6.23:16570
tcp VPN: public --> public 10.254.253.25:46054 --> 172.24.6.162:7181
icmp VPN: public --> public 10.90.145.13:31726 --> 172.24.8.38:2048
sctp VPN: public --> public 172.24.1.170:3101 --> 10.2.85.7:2905
tcp VPN: public --> public 172.24.8.137:24992 --> 172.24.8.76:8089
tcp VPN: public --> public 10.254.253.25:42192 --> 172.24.6.162:7081
tcp VPN: public --> public 10.254.253.25:41974 --> 172.24.6.162:7081
icmp VPN: public --> public 10.90.145.13:31750 --> 172.24.2.166:2048
tcp VPN: public --> public 192.168.202.11:44462 --> 172.24.6.162:7081
tcp VPN: public --> public 192.168.202.11:44368 --> 172.24.6.162:7081
icmp VPN: public --> public 172.24.6.99:40522 --> 172.24.6.1:2048
tcp VPN: public --> public 10.254.253.25:42188 --> 172.24.6.162:7081
tcp VPN: public --> public 192.168.202.11:44452 --> 172.24.6.162:7081
tcp VPN: public --> public 172.24.8.21:34592 --> 172.24.8.137:8084
tcp VPN: public --> public Remote 192.141.246.54:43930 --> 172.24.6.23:16560
tcp VPN: public --> public 192.168.202.11:44468 --> 172.24.6.162:7081
icmp VPN: public --> public 172.24.6.199:37977 --> 10.1.12.12:2048
tcp VPN: public --> public 172.24.7.37:58019 --> 172.24.7.118:8088
tcp VPN: public --> public 172.24.6.150:63850 --> 10.254.253.11:2222
tcp VPN: public --> public 172.24.8.23:31378 --> 192.141.246.100:2276
tcp VPN: public --> public 10.254.253.25:41850 --> 172.24.6.162:7081
tcp VPN: public --> public Remote 172.24.8.137:37634 --> 172.24.8.15:13101
snmp VPN: public --> public 10.90.145.20:58981 --> 172.24.4.5:161
---- More^M ----^[[42D ^[[42D icmp VPN: public --> public 172.24.3.210:8442 --> 172.24.4.27:2048
tcp VPN: public --> public 10.254.253.25:46340 --> 172.24.6.162:7181
tcp VPN: public --> public 10.254.253.25:41808 --> 172.24.6.162:7081
tcp VPN: public --> public 10.254.253.25:41992 --> 172.24.6.162:7081
tcp VPN: public --> public 10.254.253.25:42202 --> 172.24.6.162:7081
Este script elimina los caracteres especiales y columnas no necesarias de archivo.txt
while read in; do echo "$in"| rev ; done < au.txt | cut -d ':' -f1-3 | rev
De esto:
---- More^M ----^[[42D ^[[42D tcp VPN: public --> public 10.8.73.91:40168 --> 172.24.6.23:16570
A esto:
public --> public 10.8.73.91:40168 --> 172.24.6.23:16570