Skip to main content

How to find numbers in a textfile theythat are not divisible by 4096 and, round them up and write the file new file?

In Linux there is a file numbers.txt. In there areIt contains a few numbers, all separated with space.

There are numbers like this: 5476089856 71788143 9999744134 114731731 3179237376

In this example only the first and the last numbers are divisible by 4096. All others are not divisible by 4096. I need all numbers divisible by 4096.

The numbers which are not divisble by 4096 should be rounded up. The other ones should be untouched.

All of them I need written to a new file numbers_4096.txt.

Numbers like the second 71788143 must be rounded up to 71790592. 9999744134 to 9999745024 and so on...

Numbers like 5476089856 and 3179237376 should not be changed, they are divisible by 4096.

This script can do this with a single number:

#!/bin/sh

number=9999744134
divisor=4096

remainder=$((number % divisor))
new_number=$((number - remainder))
roundedup=$((new_number + divisor))

echo "Original number: $number"
echo "Divisor: $divisor"
echo "New number (divisible by $divisor): $new_number"
echo "Roundedup Number (divisible by $divisor): $roundedup"

But how to do that with a whole list that has to be rewritten and rounded up into a new file?

This script adds 4096 to numbers which are divisible by 4096, that is not what I want.

How to find numbers in textfile they are not divisible by 4096 and round them up and write the file new

In Linux there is a file numbers.txt. In there are a few numbers, all separated with space.

There are numbers like this: 5476089856 71788143 9999744134 114731731 3179237376

In this example only the first and the last numbers are divisible by 4096. All others are not divisible by 4096. I need all numbers divisible by 4096.

The numbers which are not divisble by 4096 should be rounded up. The other ones should be untouched.

All of them I need written to a new file numbers_4096.txt.

Numbers like the second 71788143 must be rounded up to 71790592. 9999744134 to 9999745024 and so on...

Numbers like 5476089856 and 3179237376 should not be changed, they are divisible by 4096.

This script can do this with a single number:

#!/bin/sh

number=9999744134
divisor=4096

remainder=$((number % divisor))
new_number=$((number - remainder))
roundedup=$((new_number + divisor))

echo "Original number: $number"
echo "Divisor: $divisor"
echo "New number (divisible by $divisor): $new_number"
echo "Roundedup Number (divisible by $divisor): $roundedup"

But how to do that with a whole list that has to be rewritten and rounded up into a new file?

This script adds 4096 to numbers which are divisible by 4096, that is not what I want.

How to find numbers in a textfile that are not divisible by 4096, round them up and write new file?

In Linux there is a file numbers.txt. It contains a few numbers, all separated with space.

There are numbers like this: 5476089856 71788143 9999744134 114731731 3179237376

In this example only the first and the last numbers are divisible by 4096. All others are not divisible by 4096. I need all numbers divisible by 4096.

The numbers which are not divisble by 4096 should be rounded up. The other ones should be untouched.

All of them I need written to a new file numbers_4096.txt.

Numbers like the second 71788143 must be rounded up to 71790592. 9999744134 to 9999745024 and so on...

Numbers like 5476089856 and 3179237376 should not be changed, they are divisible by 4096.

This script can do this with a single number:

#!/bin/sh

number=9999744134
divisor=4096

remainder=$((number % divisor))
new_number=$((number - remainder))
roundedup=$((new_number + divisor))

echo "Original number: $number"
echo "Divisor: $divisor"
echo "New number (divisible by $divisor): $new_number"
echo "Roundedup Number (divisible by $divisor): $roundedup"

But how to do that with a whole list that has to be rewritten and rounded up into a new file?

This script adds 4096 to numbers which are divisible by 4096, that is not what I want.

Became Hot Network Question
edited tags
Link
ilkkachu
  • 147.8k
  • 16
  • 268
  • 441
deleted 6 characters in body
Source Link
Banana
  • 241
  • 7

In Linux there is a file numbers.txt. In there are a few numbers, all separated with space-sings.

There are numbers like this: 5476089856 71788143 9999744134 114731731 3179237376

In this example only the first and the last numbers are divisible by 4096. All others are not divisible by 4096. I need all numbers divisible by 4096.

The numbers which are not divisble by 4096 should be rounded up. The other ones should be untouched.

All of them I need written to a new file numbers_4096.txt.

Numbers like the second 71788143 must be rounded up to 71790592. 9999744134 to 9999745024 and so on...

Numbers like 5476089856 and 3179237376 should not be changed, they are divisible by 4096.

This script can do this with a single number:

#!/bin/sh

number=9999744134
divisor=4096

remainder=$((number % divisor))
new_number=$((number - remainder))
roundedup=$((new_number + divisor))

echo "Original number: $number"
echo "Divisor: $divisor"
echo "New number (divisible by $divisor): $new_number"
echo "Roundedup Number (divisible by $divisor): $roundedup"

But how to do that with a whole list that has to be rewritten and rounded up into a new file?

This script adds 4096 to numbers which are divisible by 4096, that is not what I want.

In Linux there is a file numbers.txt. In there are a few numbers, all separated with space-sings.

There are numbers like this: 5476089856 71788143 9999744134 114731731 3179237376

In this example only the first and the last numbers are divisible by 4096. All others are not divisible by 4096. I need all numbers divisible by 4096.

The numbers which are not divisble by 4096 should be rounded up. The other ones should be untouched.

All of them I need written to a new file numbers_4096.txt.

Numbers like the second 71788143 must be rounded up to 71790592. 9999744134 to 9999745024 and so on...

Numbers like 5476089856 and 3179237376 should not be changed, they are divisible by 4096.

This script can do this with a single number:

#!/bin/sh

number=9999744134
divisor=4096

remainder=$((number % divisor))
new_number=$((number - remainder))
roundedup=$((new_number + divisor))

echo "Original number: $number"
echo "Divisor: $divisor"
echo "New number (divisible by $divisor): $new_number"
echo "Roundedup Number (divisible by $divisor): $roundedup"

But how to do that with a whole list that has to be rewritten and rounded up into a new file?

This script adds 4096 to numbers which are divisible by 4096, that is not what I want.

In Linux there is a file numbers.txt. In there are a few numbers, all separated with space.

There are numbers like this: 5476089856 71788143 9999744134 114731731 3179237376

In this example only the first and the last numbers are divisible by 4096. All others are not divisible by 4096. I need all numbers divisible by 4096.

The numbers which are not divisble by 4096 should be rounded up. The other ones should be untouched.

All of them I need written to a new file numbers_4096.txt.

Numbers like the second 71788143 must be rounded up to 71790592. 9999744134 to 9999745024 and so on...

Numbers like 5476089856 and 3179237376 should not be changed, they are divisible by 4096.

This script can do this with a single number:

#!/bin/sh

number=9999744134
divisor=4096

remainder=$((number % divisor))
new_number=$((number - remainder))
roundedup=$((new_number + divisor))

echo "Original number: $number"
echo "Divisor: $divisor"
echo "New number (divisible by $divisor): $new_number"
echo "Roundedup Number (divisible by $divisor): $roundedup"

But how to do that with a whole list that has to be rewritten and rounded up into a new file?

This script adds 4096 to numbers which are divisible by 4096, that is not what I want.

added 1 character in body
Source Link
Hauke Laging
  • 94.5k
  • 21
  • 132
  • 185
Loading
edited tags
Link
Banana
  • 241
  • 7
Loading
added 108 characters in body
Source Link
Banana
  • 241
  • 7
Loading
Source Link
Banana
  • 241
  • 7
Loading