0

I have this file, ipaddresses.txt

152.48.64.13
146.112.164.43
236.157.219.229
188.201.225.93
193.140.79.73
...

And this file, cidr.txt

20
21
8
20
21
...

And I want the output file to be like this:

152.48.64.13/20
146.112.164.43/21
236.157.219.229/8
188.201.225.93/20
193.140.79.73/21
...

How to achieve this?

10
  • 5
    Why sed, specifically? have you considered alternatives - such as paste -d/ ipaddresses.txt cidr.txt ? Jul 21, 2019 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, 2019 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? Jul 21, 2019 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, 2019 at 23:53
  • 2
    @Annahri do your files have Windows style (CRLF) line endings by any chance? Jul 21, 2019 at 23:54

1 Answer 1

2

You want to use paste:

$ paste -d '/' ipaddresses.txt cidr.txt
152.48.64.13/20
146.112.164.43/21
236.157.219.229/8
188.201.225.93/20
193.140.79.73/21
.../...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .