1

Good morning all, I have a series of files in which some lines are text-only and do not matter, and others which look like this:

    size=xxxx

These numbers range from single-digit to six digits. What I would like to do is divide every number in the file by 10, with a minimum of 1, and with all remaining whole numbers. Something just as good can be achieved by deleting the last digit in every line which ends with a number of some sort (I can then find and replace those lines which deleted the only digit). So, for instance

    size=32451
    ...
    size=9423
    ...
    size=123452
    ...
    size=3
    ...
    size=31

becomes

    size=3245
    ...
    size=942
    ...
    size=12345
    ...
    size=1
    ...
    size=3

Is there an easy way to do this?

Thank you

  • 1
    What software or programming language are you using? – logi-kal May 21 '17 at 12:53
  • 1
    size=3 becomes size=1?? – Gurmanjot Singh May 21 '17 at 12:53
  • 1
    Please **clarify your specific problem or add additional details to highlight exactly what you need**. As it's currently written, it’s hard to tell exactly what you're asking. See the [How to Ask](http://stackoverflow.com/help/how-to-ask) page for help clarifying this question – Pedro Lobito May 21 '17 at 13:08

1 Answers1

2

If your software/programming language allows you to use conditional replacement (e.g. Notepad++), replace:

(?<=size=)(\d{1,5})?\d

with (?1\1:1) (or (?1$1:1)).

Otherwise, you have to do 2 separate replacements: first replace: (?<=size=)(\d{1,5})\d with \1 (or $1), then (?<=size=)\d with 1.

logi-kal
  • 7,107
  • 6
  • 31
  • 43