0

A bit of context: the File I've shown below is generated by a VLSI tool. It consists of timing delays caused by various components in a circuit. When I generate this "timing file" the fields are not properly organised sometimes.

The generated file:

something1                 0.20   0.00   0.00 
something2 6    12.95 
something3        0.00     0.08   0.00   0.00   0.07 
something4   6    8.70 
something5        0.00     0.03   0.00   0.00   0.05 
something6   5    4.70

What I want:

something1                 0.20   0.00   0.00 
something2   6    12.95 
something3        0.00     0.08   0.00   0.00   0.07 
something4   6    8.70 
something5        0.00     0.03   0.00   0.00   0.05 
something6   5    4.70

The displacement for  something4 and something6keep recurring throughout the table in a particular order(say every 2 lines or 1 line). Only something2 has a different displacement whereas all the other displacements follow something4/something6.

So far I have no clue how to proceed with this. Any way to fix this?

LowerMoon
  • 61
  • 5
  • 1
    Welcome to SO. Stack Overflow is a question and answer site for professional and enthusiast programmers. The goal is that you add some code of your own to your question to show at least the research effort you made to solve this yourself. – Cyrus Sep 11 '18 at 09:49
  • 2
    Duplicate of https://stackoverflow.com/questions/52245217/how-to-correct-displaced-columns-in-unix. – melpomene Sep 11 '18 at 10:12
  • Possible duplicate of [How to correct displaced columns in unix](https://stackoverflow.com/questions/52245217/how-to-correct-displaced-columns-in-unix) – Cyrus Sep 11 '18 at 10:42
  • And there is no header row? – James Brown Sep 11 '18 at 10:43
  • and possible duplicate of [Replace empty spaces in a column with a character](https://stackoverflow.com/q/52215559/3776858) – Cyrus Sep 11 '18 at 10:45
  • 2 of the suggested duplicates refer to an unanswered question by the same author and the third to an answered question which does not address the same problem. – James Brown Sep 11 '18 at 11:13
  • Yes I posted this question again because apparently my previous question was too vague, so I wrote a new one and added some background to it. – LowerMoon Sep 11 '18 at 16:18
  • This question and answers got @jww-ed (gratuitous downvotes for all, almost certainly from user @jww) - please upvote everything to compensate, thanks. – Ed Morton Sep 15 '18 at 19:47

2 Answers2

0
$ awk '{gsub(/ {6}/,","); gsub(/ +/,",")} 1' file | column -s, -t
something1            0.20  0.00  0.00
something2  6  12.95
something3     0.00   0.08  0.00  0.00  0.07
something4  6  8.70
something5     0.00   0.03  0.00  0.00  0.05
something6  5  4.70

or:

$ awk 'BEGIN{FS=OFS="\t"} {gsub(/ {6}/,FS); gsub(/ +/,FS); $1=$1} 1' file
something1                      0.20    0.00    0.00
something2      6       12.95
something3              0.00    0.08    0.00    0.00    0.07
something4      6       8.70
something5              0.00    0.03    0.00    0.00    0.05
something6      5       4.70
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
0

Another way with awk

awk 'NF>3{$2=OFS$2}NF==4{$2=OFS$2}{$1=$1}1' OFS='\t' infile
ctac_
  • 2,413
  • 2
  • 7
  • 17