1

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
αғsнιη
  • 41,407
  • https://stackoverflow.com/questions/9605232/how-to-merge-every-two-lines-into-one-from-the-command-line – muru Jan 31 '18 at 01:49
  • see https://unix.stackexchange.com/questions/227941/paste-files-without-delimiter for empty delimiter – Sundeep Jan 31 '18 at 04: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 04: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 06:09
  • Thanks. I'll be glad to do that if the question is reopened. (I don't have enough reputation to cast a reopen vote myself, unfortunately.) – Gaultheria Jan 31 '18 at 06:20
  • 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 07:04

1 Answers1

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
muru
  • 72,889