reformating一个文本文件 [英] reformating a text file

查看:135
本文介绍了reformating一个文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找了现有的答案,但很茫然。

I've looked for existing answers, but am at a loss.

我需要一个纯文本文件:

I need to take a plain text file:

1 - 轮小数到十分之一。

1 - round decimals to tenths

2 - 数字的最后一组需要为四个字符,可以使用零填写

2 - last group of numbers need to be four characters long, using zero to fill

3 - 删除时期 - 发现SED解决方案

3 - remove periods - found sed solution

4 - 删除空格 - 发现SED解决方案

4 - remove spaces - found sed solution

这里是我的工作文件的例子

here is an example of the file I'm working with

5.41   3.08  795
4.82   2.69   19
3.60   2.83    8
4.24   3.10 1559

需要被更改为:

54310795
48270019
36280008
42311559

由于安迪 -

Thanks - Andy

推荐答案

您可以做到这一点的一次性使用awk:

you can do it in one-shot with awk:

 awk '{$0=sprintf("%.1f%.1f%04d", $1,$2,$3);gsub(/\./,"")}1' file 

测试:

kent$  cat file
5.41   3.08  795
4.82   2.69   19
3.60   2.83    8
4.24   3.10 1559

kent$  awk '{$0=sprintf("%.1f%.1f%04d", $1,$2,$3);gsub(/\./,"")}1' file
54310795
48270019
36280008
42311559

这篇关于reformating一个文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆