1

I need to reformat the kegg reconstruct pathway output, I have something like this in file1:

00550 Peptidoglycan biosynthesis (2)

K01000

K02563

00511 Other glycan degradation (8)

K01190

K01191

K01192

K01201

K01227

K12309

I need something like:

00550 Peptidoglycan biosynthesis (2)   K01000   K02563
00511 Other glycan degradation (6)   K01190   K01191   K01192   K01201   K01227   K12309

How could I reformat this like that in vim or linux

2
  • 1
    This can be done using a :g command. Something like this: g/^0/,/^0\|\%$/-j, which will mark each line starting with 0 and join until the next line starting with 0 (or end of line). However, it will miss the last line, so you need to add a final :$-j command to fix this. Posting here as comment, since question is on hold and answers can't be written Oct 23, 2018 at 12:56
  • @ChristianBrabandt the original question asked "how can I do that on linux or python" that's why I closed it. IMO it still lacks some details to be really useful but you can post your answer.
    – statox
    Oct 23, 2018 at 12:58

1 Answer 1

1

This can be done using a :g command.

Something like this:

g/^0/,/^0\|\%$/-j

This will mark each line (e.g. on which lines to act) starting with 0 and join until the next line starting with 0 (or end of line).

However, it will miss the last line, so you need to add a final

:$-j 

command to fix this

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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