Bash or python for changing spacing in files

Posted by Werner on Stack Overflow See other posts from Stack Overflow or by Werner
Published on 2010-03-23T13:47:52Z Indexed on 2010/03/23 14:03 UTC
Read the original article Hit count: 260

Filed under:
|

Hi,

I have a set of 10000 files. In all of them, the second line, looks like:

AAA 3.429 3.84

so there is just one space (requirement) between AAA and the two other columns. The rest of lines on each file are completely different and correspond to 10 columns of numbers.

Randomly, in around 20% of the files, and due to some errors, one gets

BBB  3.429 3.84

so now there are two spaces between the first and second column.

This is a big error so I need to fix it, changing from 2 to 1 space in the files where the error takes place.

The first approach I thought of was to write a bash script that for each file reads the 3 values of the second line and then prints them with just one space, doing it for all the files.

I wonder what do oyu think about this approach and if you could suggest something better, bashm python or someother approach.

Thanks

© Stack Overflow or respective owner

Related posts about bash

Related posts about python