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?

  • 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
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
.../...
| 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.