Executing the script with the space after "conv:" the results is a "newline" as below:
    lines = lines.replace("www.","conv: ")
conv:
yahoo.com
conv:
yahoo.it
conv:
yahoo.org
conv:
yahoo.net
how remove \n (new line)?
removing the space character after conv: the script runs perfectly.
#!/usr/bin/python
with open('/home/user/tmp/prefix.txt') as f:
    lines = f.read()
    lines = lines.replace("http://","")
    lines = lines.replace("www.","conv:")
    urls = [url.split('/')[0] for url in lines.split()]
    print ('\n'.join(urls))
results is:
conv:yahoo.com
conv:yahoo.it
conv:yahoo.org
conv:yahoo.net
I'd like have:
conv: yahoo.com
conv: yahoo.it
conv: yahoo.org
conv: yahoo.net
                The line
urls = [url.split('/')[0] for url in lines.split()]
splits your lines on a space, so you'll get the conv: part as a single url.
You could do
urls = [url.split('/')[0].replace("conv:", "conv: ") for url in lines.split()]
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With