I have this file, ipaddresses.txt

And this file, cidr.txt


And I want the output file to be like this:

How to achieve this?

  • 5
    Why sed, specifically? have you considered alternatives - such as paste -d/ ipaddresses.txt cidr.txt ? – steeldriver Jul 21 '19 at 23:01
  • Because I only know sed to do this kind of task, I will edit my thread. By the way, I tried using paste, it doesn't append to the last line, but it append a new line each. – annahri Jul 21 '19 at 23:14
  • 1
    @Annahri The paste command by steeldriver works. Do you not have GNU paste or is there something with your environment such as an alias? – Nasir Riley Jul 21 '19 at 23:36
  • @NasirRiley I'm using bash on Ubuntu on Windows 10 (what is the correct term for this?) I did paste -d/ ipaddresses.txt cidr.txt > out.txt. When I try to do it without outputting a file, It prints a different behaviour. It adds \ in the beginning of each line but It does correctly for the very last line. Hmm – annahri Jul 21 '19 at 23:53
  • 2
    @Annahri do your files have Windows style (CRLF) line endings by any chance? – steeldriver Jul 21 '19 at 23:54

You want to use paste:

$ paste -d '/' ipaddresses.txt cidr.txt
| improve this answer | |

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.