Sed substitution possible with arithmetic involved?

前端 未结 4 1681
眼角桃花
眼角桃花 2020-12-16 21:18

File I need to modify contains the following:

block: 16, size: 16, start: 8, length: 4

I\'d like the file so that values for block<

4条回答
  •  难免孤独
    2020-12-16 22:07

    Perl is useful here:

    perl -pe '
      s{(\D+)(\d+)(\D+)(\d+)(\D+)(\d+)(\D+)(\d+)}
       {$1 . $2/2 . $3 . $4/2 . $5 . $6*2 . $7 . $8*2}e
    ' file
    

    If you want to edit your files in-place, perl has a -i option like sed.

提交回复
热议问题