1

This question already has an answer here:

I have about 500 files of text files similar to the output below.

GigabitEthernet15/0/
1                                                               
GigabitEthernet16/0/
1                                                               
GigabitEthernet16/1/
1                                                               
GigabitEthernet15/1/
1

My goal is to have it look like this:

GigabitEthernet15/0/1                                                               
GigabitEthernet16/0/1                                                               
GigabitEthernet16/1/1                                                               
GigabitEthernet15/1/1

marked as duplicate by Jeff Schaller, muru, G-Man, Sundeep, αғsнιη Jan 31 '18 at 4:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • see unix.stackexchange.com/questions/227941/… for empty delimiter – Sundeep Jan 31 '18 at 4:43
  • 1
    This might not be a duplicate, since the OP might not want to join every pair of lines. If there's a chance that the input will be more complex than in the OP's example, it may be helpful to trigger the joining when a particular pattern occurs. EG, awk '{ printf "%s", $0 } $0 !~ /^GigabitEthernet.*\/$/ { printf RS }' file.txt – Gaultheria Jan 31 '18 at 4:58
  • @Gaultheria It turned out this is exactly what I needed, I had some other examples that misbehaved. If you want to put your comment as an answer, I will mark it correct. Thank you! – Jordan Head Jan 31 '18 at 6:09
  • 1
    @JordanHead in that case you should add a sample input to the question that reflects your use case better... also, you are expected to show what efforts you made to solve this by yourself, hover the mouse over downvote button to see it for yourself – Sundeep Jan 31 '18 at 7:04
3

With awk, get the next line and append it to the current line:

$ awk '{getline n; $0 = $0 n} 1' foo
GigabitEthernet15/0/1
GigabitEthernet16/0/1
GigabitEthernet16/1/1
GigabitEthernet15/1/1

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