0

I have a text file of X ips and X files that looks like:

ip1
ip2
ip3
some_dir/file1
some_dir/file2
some_dir/file3

I'd like to combine the lines into a csv format, like:

ip1,some_dir/file1
ip2,some_dir/file2
ip3,some_dir/file3

Any suggestions on how this could be on? Thanks!

7
  • 2
    Welcome to Vi&Vim SE. See if the answers here help: Add a block of text to end of lines (and don't forget to upvote any that do :)
    – B Layer
    Jan 4, 2022 at 22:46
  • Hint: in the accepted answer under "Dash-delimited" is a solution that should work for your problem. First, put a blank line between your two blocks, then put the cursor on the i of ip1. Then use the solution as written except change the space-dash-space to a comma.
    – B Layer
    Jan 4, 2022 at 23:15
  • @BLayer hey, thanks for the help! What you linked does look like what I'm trying to do but I'm not familiar with how to use the command, it looks like a list of instructions. Jan 4, 2022 at 23:40
  • Right, here's the (amended) sequence: mt<C-V>}mb<BS>$A,<Esc>gvd'bjPkd't. While in Normal mode you'll want to type those characters literally except for the parts of the form <X>. Those are, respectively, Ctrl-V, Backspace and Escape.
    – B Layer
    Jan 4, 2022 at 23:43
  • Oh ok awesome, that worked! I didn't realized it was key strokes. Thank you! Jan 5, 2022 at 0:06

0

Browse other questions tagged or ask your own question.