Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a text file imported from Excel 2003 in the following basic format.

43038    12500    s.ramesh    labour

43038    13000    m.ramesh    doctor

I have to arrange this file in such a format that column 1 should be from 1-5.

The problem is that columns 2,3 and 4 are not arranged in the particular order.

I want this file in such an order that

  • column 2 of the entire file should be in the 15-19 place
  • column 3 should be in 49-65
  • column 4 should be in 75-95th position

The file has 100000 rows and 4 columns plz.

I am looking for advice on whether sort, vi, or any other editor or shell would be helpful, because I have to do this for about 100 files daily.

share|improve this question

A scripting language like Perl is ideal for this.

$ cat t2
5 2 r.gritty teaboy
43038 12500 s.ramesh labour
43038 13000 m.ramesh doctor

$ perl -ane 'printf("%5s %5s\n", $F[2],$F[1])' t2
r.gritty     2
s.ramesh 12500
m.ramesh 13000


$ perl  -ane 'printf("%5s %0.5d\n", $F[2],$F[1])' t2
r.gritty 00002
s.ramesh 12500
m.ramesh 13000

Then to edit hundreds of files inplace all in one go

$ perl -i -ane 'printf("%5s %5s\n", $F[2],$F[1])' t1 t2 t3 t4 t5 *.txt foo/t6
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .