Skip to main content
Only overwrite if Awk was successful
Source Link
Quasímodo
  • 19.4k
  • 4
  • 41
  • 78

Sed is not made for arithmetics. You could try clumsy workarounds, but Awk is better in that regard:

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file 

With GNU Awk, add -i inplace to edit the file inplace. If you don't have GNU Awk, you can use sponge

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file | sponge file 

or use the good old overwriting (it's what happens under the hood anyway...)

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file > newfile && mv newfile file 

Sed is not made for arithmetics. You could try clumsy workarounds, but Awk is better in that regard:

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file 

With GNU Awk, add -i inplace to edit the file inplace. If you don't have GNU Awk, you can use sponge

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file | sponge file 

or use the good old overwriting (it's what happens under the hood anyway...)

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file > newfile mv newfile file 

Sed is not made for arithmetics. You could try clumsy workarounds, but Awk is better in that regard:

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file 

With GNU Awk, add -i inplace to edit the file inplace. If you don't have GNU Awk, you can use sponge

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file | sponge file 

or use the good old overwriting (it's what happens under the hood anyway...)

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file > newfile && mv newfile file 
Alternatives to applying changes to the file
Source Link
Quasímodo
  • 19.4k
  • 4
  • 41
  • 78

Sed is not made for arithmetics. You could try clumsy workarounds, but Awk is better in that regard:

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file 
 

With GNU awkAwk, add -i inplace to edit the file inplace. If you don't have GNU Awk, you can use sponge

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file | sponge file 

or use the good old overwriting (it's what happens under the hood anyway...)

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file > newfile mv newfile file 

Sed is not made for arithmetics. You could try clumsy workarounds, but Awk is better in that regard:

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file 

With GNU awk, add -i inplace to edit the file inplace.

Sed is not made for arithmetics. You could try clumsy workarounds, but Awk is better in that regard:

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file 
 

With GNU Awk, add -i inplace to edit the file inplace. If you don't have GNU Awk, you can use sponge

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file | sponge file 

or use the good old overwriting (it's what happens under the hood anyway...)

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file > newfile mv newfile file 
Source Link
Quasímodo
  • 19.4k
  • 4
  • 41
  • 78

Sed is not made for arithmetics. You could try clumsy workarounds, but Awk is better in that regard:

awk '!/^[#@]/{printf("%.1f\n",$2*10)}' file 

With GNU awk, add -i inplace to edit the file inplace.