IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Shell et commandes GNU Discussion :

Modification de fichier avec gsed sur macOS


Sujet :

Shell et commandes GNU

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    320
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 320
    Par défaut Modification de fichier avec gsed sur macOS
    Bonjour,
    Dans mon projet de cartographie, j'utilise la bibliothèque gdal via scripts bash.
    Je géoréférence des PNG (524288 PNG) pour en obtenir des TIFF en suivant cette méthode :
    PNG => gdal_translate + gdalwarp => TIFF
    Précisément :
    Code BASH : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    gdal_translate -of VRT -a_srs EPSG:4326 $F_BW_PNG $F_VRT -a_ullr $ULLR
    gdalwarp -s_srs EPSG:4326 -t_srs EPSG:3857 $F_VRT $F_TIFF
    Je souhaite faire une modification du contenu de <ColorTable>[...]</ColorTable> des fichiers VRT mais il n'est pas possible de le faire en mode natif (visiblement).
    On m'a indiqué que sed pouvait répondre à ma demande.

    # VRT original
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    <VRTDataset rasterXSize="256" rasterYSize="256">
      <SRS dataAxisToSRSAxisMapping="2,1">GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]</SRS>
      <GeoTransform> -1.8000000000000000e+02,  1.3732910156250000e-03,  0.0000000000000000e+00,  7.1718750000000000e+01,  0.0000000000000000e+00, -1.3732910156250000e-03</GeoTransform>
      <VRTRasterBand dataType="Byte" band="1">
        <Metadata domain="IMAGE_STRUCTURE">
          <MDI key="NBITS">1</MDI>
        </Metadata>
        <ColorInterp>Palette</ColorInterp>
        <ColorTable>
          <Entry c1="0" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="255" c3="255" c4="255" />
        </ColorTable>
        <SimpleSource>
          <SourceFilename relativeToVRT="0">bw_png/map_11_0_52.png</SourceFilename>
          <SourceBand>1</SourceBand>
          <SourceProperties RasterXSize="256" RasterYSize="256" DataType="Byte" BlockXSize="256" BlockYSize="1" />
          <SrcRect xOff="0" yOff="0" xSize="256" ySize="256" />
          <DstRect xOff="0" yOff="0" xSize="256" ySize="256" />
        </SimpleSource>
      </VRTRasterBand>
    </VRTDataset>

    Ici je souhaite supprimer cette partie
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
        <Metadata domain="IMAGE_STRUCTURE">
          <MDI key="NBITS">1</MDI>
        </Metadata>

    et modifier celle ci
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
        <ColorTable>
          <Entry c1="0" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="255" c3="255" c4="255" />
        </ColorTable>

    en
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
     
        <ColorTable>
          <Entry c1="0" c2="0" c3="255" c4="255" />
          <Entry c1="0" c2="255" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
          <Entry c1="255" c2="0" c3="0" c4="255" />
        </ColorTable>

    J'ai commencé a regarder sed mais c'est pas clair comme de l'eau de roche pour ma petite tête de serin ... un coup de pouce serait le bienvenu.
    Merci

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    320
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 320
    Par défaut
    Pour le delete (en m'inspirant d'exemples trouvés sur le net) ceci fonctionne
    Code BASH : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    sed '5,7d' $F_VRT
    cela implique qu'il faut que ces lignes soient toujours au même endroit (ce qui devrait être le cas logiquement) donc ça fait le job

  3. #3
    Modérateur
    Avatar de N_BaH
    Profil pro
    Inscrit en
    Février 2008
    Messages
    7 636
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 7 636
    Par défaut
    cherche plutôt le motif de départ et le motif de fin de la suppression, parce que ce que tu veux supprimer pourrait ne pas toujours être au même endroit.
    .
    N'oubliez pas de consulter les cours shell, la FAQ, et les pages man.

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    320
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 320
    Par défaut
    @N_BaH
    Yep c'est ce sur quoi je suis "tombé" pendant mes recherches mais pas très bien compris la syntaxe.
    Merci pour l'aiguillage 😉

  5. #5
    Modérateur
    Avatar de N_BaH
    Profil pro
    Inscrit en
    Février 2008
    Messages
    7 636
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 7 636
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    sed '/début/,/fin/ACTION' fichier
    .
    N'oubliez pas de consulter les cours shell, la FAQ, et les pages man.

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    320
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 320
    Par défaut
    Avec les motifs de départ et de fin ça donne ceci :

    # Suppression de
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
        <Metadata domain="IMAGE_STRUCTURE">
          <MDI key="NBITS">1</MDI>
        </Metadata>

    Code BASH : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    sed -i '/<Metadata domain="IMAGE_STRUCTURE">/,/<\/Metadata>/d' $F_VRT

    # Suppression du contenu de ColorTable
    Code BASH : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    sed -i '/<Entry c1="0" c2="0" c3="0" c4="255" \/>/,/<Entry c1="255" c2="255" c3="255" c4="255" \/>/d' $F_VRT

    # Ajout de mes valeurs dans ColorTable
    Code BASH : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    sed -i -e '/<ColorTable>/r MY_COLORTABLE.txt' $F_VRT
    MY_COLORTABLE.txt contient les 256 lignes que je souhaite insérer.

    J'ai le cerveau en ébullition 🤯, doit il y avoir moyen de faire plus simple, nan ?

  7. #7
    Modérateur
    Avatar de N_BaH
    Profil pro
    Inscrit en
    Février 2008
    Messages
    7 636
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 7 636
    Par défaut
    je ne crois pas qu'il y ait plus simple.
    mais tu dois pouvoir tout faire avec une seule commande sed :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    sed -i bak '/début1/,/fin1/d ; /début2/,/fin2/d; /motif/r fichier.replace' fichier.in
    ...
    ?
    .
    N'oubliez pas de consulter les cours shell, la FAQ, et les pages man.

  8. #8
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    320
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 320
    Par défaut
    Ah ok je peux grouper tout ça ...
    Je teste ça de suite, merci

  9. #9
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    320
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 320
    Par défaut
    Parfait, ça fait le job souhaité 😊

    Code BASH : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    sed -i '/<Metadata domain="IMAGE_STRUCTURE">/,/<\/Metadata>/d; /<Entry c1="0" c2="0" c3="0" c4="255" \/>/,/<Entry c1="255" c2="255" c3="255" c4="255" \/>/d; /<ColorTable>/r MY_COLORTABLE.txt' $F_VRT

    PS : le bak n'est pas pris en compte et retourne une erreur, je suppose qu'il était là pour une sauvegarde de l'original.

    Merci beaucoup @N_BaH j'aurais pas a me faire les 524288 fichiers à la main (et c'est pas pour me déplaire) 😉

  10. #10
    Expert confirmé
    Homme Profil pro
    Développeur informatique en retraite
    Inscrit en
    Avril 2008
    Messages
    2 102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : Développeur informatique en retraite

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 102
    Par défaut
    Citation Envoyé par rlelamer Voir le message
    PS : le bak n'est pas pris en compte et retourne une erreur, je suppose qu'il était là pour une sauvegarde de l'original.
    Ça dépend de la version de sed qui est souvent liée au système d'exploitation.

    Par exemple, sous macos, on a (si je ne me trompe pas) la version posix du sed de BSD, où l'extension de sauvegarde pour l'option -i est carrément obligatoire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    $ man sed | head
     
    SED(1)                    BSD General Commands Manual                   SED(1)
     
    NAME
         sed -- stream editor
     
    SYNOPSIS
         sed [-Ealn] command [file ...]
         sed [-Ealn] [-e command] [-f command_file] [-i extension] [file ...]
    En général, sous linux, on a plutôt un GNU sed, dont le gsed de macos est assez proche et où l'extension de l'option -i est optionnelle:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    SED(1)                                                                               User Commands                                                                               SED(1)
     
    NAME
           sed - stream editor for filtering and transforming text
     
    SYNOPSIS
           sed [OPTION]... {script-only-if-no-other-script} [input-file]...
     
    DESCRIPTION
           Sed  is  a stream editor.  A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).  While in some ways similar to an
           editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient.  But it is sed's  ability  to  filter
           text in a pipeline which particularly distinguishes it from other types of editors.
     
           -n, --quiet, --silent
     
                  suppress automatic printing of pattern space
     
           -e script, --expression=script
     
                  add the script to the commands to be executed
     
           -f script-file, --file=script-file
     
                  add the contents of script-file to the commands to be executed
     
           --follow-symlinks
     
                  follow symlinks when processing in place
     
           -i[SUFFIX], --in-place[=SUFFIX]
     
                  edit files in place (makes backup if SUFFIX supplied)
    ...
    Apparemment, dans la version que tu as, l'option -i ne supporte pas l'extension pour une sauvegarde.

  11. #11
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    320
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 320
    Par défaut
    Bonjour,
    Oui effectivement je suis sous macOS mais j'utilise pas le sed natif mais gsed (brew install gsed)

    Via la commande ci dessus j'ai pu effectuer le traitement sur les 524288 VRT sans soucis 😉

  12. #12
    Expert confirmé
    Homme Profil pro
    Développeur informatique en retraite
    Inscrit en
    Avril 2008
    Messages
    2 102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : Développeur informatique en retraite

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 102
    Par défaut
    Citation Envoyé par rlelamer Voir le message
    Bonjour,
    Oui effectivement je suis sous macOS mais j'utilise pas le sed natif mais gsed (brew install gsed)
    #1 Juste pour info:
    Ce forum est en principe réservé aux environnements linux.
    Du coup, je vois 2 possibilités (sous réserve d'agrément des modérateurs):
    • soit tu postes dans le "bon" forum, celui dédié aux shell-commandes-posix où tu auras environ les mêmes contributeurs qu'ici et potentiellement des contributeurs connaissant plus spécifiquement les environnements non-linux (dont macos),
    • soit tu postes quand même ici, mais en précisant ton environnement, afin d'améliorer l'efficacité des réponses, en évitant les incompréhensions, mauvaises surprises et autres fausses pistes.


    #2 Juste pour info:
    Comme je l'ai indiqué précédemment, la commande gsed de macos est assez proche du GNU sed:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    SED(1)
    NAME       sed - stream editor for filtering and transforming text
    SYNOPSIS       sed [OPTION]... {script-only-if-no-other-script} [input-file]...
    DESCRIPTION
           Sed  is  a stream editor...
     
           -e script, --expression=script
                  add the script to the commands to be executed
     
           -f script-file, --file=script-file
                  add the contents of script-file to the commands to be executed
     
           -i[SUFFIX], --in-place[=SUFFIX]
                  edit files in place (makes backup if SUFFIX supplied)
    ...
    Je t'invite à noter la différence entre les options -e ou -f, qui sont suivies d'une espace, avant l'argument qui suit, et -i, qui, sous macos, n'est PAS suivie d'espace avant le suffixe (contrairement à la version linux).

    Donc, sous macos, pour conserver une copie du fichier édité par gsed, il faut écrire, par exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    sed -i.bak '/<Metadata domain="IMAGE_STRUCTURE">/,/<\/Metadata>/d; /<Entry c1="0" c2="0" c3="0" c4="255" \/>/,/<Entry c1="255" c2="255" c3="255" c4="255" \/>/d; /<ColorTable>/r MY_COLORTABLE.txt' $F_VRT
    De cette manière, le fichier $F_VRT sera préalablement copié en ${F_VRT}.bak

  13. #13
    Modérateur
    Avatar de N_BaH
    Profil pro
    Inscrit en
    Février 2008
    Messages
    7 636
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 7 636
    Par défaut Modération
    si la discussion s'oriente franchement vers macos, je déplacerai.
    par contre, j'ajoute une précision au titre de la discussion.
    .
    N'oubliez pas de consulter les cours shell, la FAQ, et les pages man.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Modification de fichier avec sed
    Par Xam29870 dans le forum Shell et commandes GNU
    Réponses: 9
    Dernier message: 29/01/2018, 17h43
  2. Modification de fichier avec un mini programme
    Par Grenouille69 dans le forum Windows
    Réponses: 4
    Dernier message: 12/03/2016, 16h06
  3. Téléchargement fichier avec reprise sur erreur
    Par Hideman85 dans le forum Entrée/Sortie
    Réponses: 3
    Dernier message: 20/02/2015, 18h53
  4. Probleme de modification de fichier avec le lecteur wmp
    Par olafviking dans le forum Windows Forms
    Réponses: 0
    Dernier message: 26/01/2010, 23h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo