Supprimer plusieurs données avec sed
Bonjour :D
Je dispose d'un fichier 'hosts' dont voici un extrait:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| # Title: StevenBlack/hosts with the fakenews, gambling, porn and social extensions #
# This hosts file is a merged collection of hosts from reputable sources,
# with a dash of crowd sourcing via GitHub
#
# Date: 15 November 2020 18:37:51 (UTC)
# Extensions added to this file: fakenews, gambling, porn, social
# Number of unique domains: 88,597
#
# Fetch the latest version of this file: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts
# Project home page: https://github.com/StevenBlack/hosts
# Project releases: https://github.com/StevenBlack/hosts/releases
#
# ===============================================================
127.0.0.1 localhost
127.0.0.1 localhost.localdomain
127.0.0.1 local
255.255.255.255 broadcasthost
::1 localhost
::1 ip6-localhost
::1 ip6-loopback
fe80::1%lo0 localhost
ff00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
0.0.0.0 0.0.0.0
# Custom host records are listed here.
# End of custom host records.
# Start StevenBlack
#=====================================
# Hosts contributed by Steven Black
# http://stevenblack.com
0.0.0.0 n2019cov.000webhostapp.com
0.0.0.0 webmail-who-int.000webhostapp.com
0.0.0.0 010sec.com
0.0.0.0 01mspmd5yalky8.com |
Avec le code suivant:
Code:
1 2 3 4 5
|
cat "t_f" |\
sed -r -e 's/#.*//g' \
-e '/^\s*$/d' \
-e 's/\r//g' >> "$p_f" |
Je parviens à supprimer tous les commentaires commençons par '#', les lignes vides et les retours à la ligne.
Ce qui donne:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| 127.0.0.1 localhost
127.0.0.1 localhost.localdomain
127.0.0.1 local
255.255.255.255 broadcasthost
::1 localhost
::1 ip6-localhost
::1 ip6-loopback
fe80::1%lo0 localhost
ff00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
0.0.0.0 0.0.0.0
0.0.0.0 n2019cov.000webhostapp.com
0.0.0.0 webmail-who-int.000webhostapp.com
0.0.0.0 010sec.com
0.0.0.0 01mspmd5yalky8.com |
Je dois également supprimer toutes les parties en bleue mais à ce stade, je bloque. Un petit coup de main s'il vous plaît ?
En vous remerciant par avance :mrgreen: