0

In command paste - - - -, numbers of - is equal the future column number. In my case, I have 55,000 future column, for me wont need to put 55,000 - what I will can use?

Example:

title1:A1
title2:A2
title3:A3
title4:A4
title5:A5

title1:B1
title2:B2
title3:B3
title4:B4
title5:B5

title1:C1
title2:C2
title3:C3
title4:C4
title5:C5

title1:D1
title2:D2
title3:D3
title4:D4
title5:D5

I want to transform this file (A) into following:

title1 A1   title1 B1   title1 C1   title1 D1   title2 A2
title2 B2   title2 C2   title2 D2   title3 A3   title3 B3
title3 C3   title3 D3   title4 A4   title4 B4   title4 C4
title4 D4   title5 A5   title5 B5   title5 C5   title5 D5

For this, I used :

$ sed 's/:/ /; /^$/d' sample.txt \
    | sort | paste - - - - -

But in my file, I will have a big column number: 55,000 or 400 column. What is the other form to replace the - ??

  • Is that output what you really wanted? A mix of different titles across the line (eg line 1 has 4 "title1" and 1 "title2". – Stephen Harris Jul 13 '16 at 12:21
  • @sthephenharris I'm sorry, In output I want only the "title1" in line 1, only "title 2" in line 2, etc. Because after I want that beeing : (Line1) title1 a1 b1 c1 d1 (Line2) title2 a2 b2 c2 d2 Do you understand what I wanted? – Amanda Botelho Alvarenga Jul 13 '16 at 12:24
  • try paste $(for i in {1..400}; do echo -n '- '; done) or whatever number you want.. got idea from stackoverflow.com/a/5349772/4082052 – Sundeep Jul 13 '16 at 12:26
  • or paste $(printf -- "- %.s" {1..400}) – Sundeep Jul 13 '16 at 12:36
  • 1
    Clarification needed: Is the output a diagonal transpose, (i.e. the current output column#1 has {A1,B2,C2...}), or was that a typo for a regular transpose, (in which case column #1 would be {A1,A2,A3...})? – agc Jul 13 '16 at 13:47
0

String multiplication trick based on this answer: https://stackoverflow.com/a/5349772/4082052


Use substitution to insert programmable number of dashes

paste $(for i in {1..400}; do echo -n '- '; done)

or

paste $(printf -- "- %.s" {1..400})

To know why printf -- was used: Dashes in printf

0

For a file with 4 rows:

 paste $(for((i=1;i<4;i++)); do echo -n "- "; done; echo -n "-") < file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.