1

I tried the following commands:

  1. Running the line below gives the output text mentioned.

    cat $tmp_list_address | sort | uniq | sed 's/^/address=\//;s/$/\/192.168.1.1/' > $tmp_list_final
    
  2. Running the line below gives the output text mentioned.

    sed -i 's/.*/address=&\/192.168.1.1/' $tmp_list_address
    
  3. I even tried doing things separately. The following adds the address= part. but when it tries to add the IP at the end, it changes to the output text below.

    sed -i 's/^/address=/' $tmp_list_address
    sed -i 's/$/$pixelserv_ip/' $tmp_list_ip
    

The original list is the one I am trying to get, where blanks and white spaces are also being saved, and I am removing them before trying to add text.

curl -s http://www.malwaredomainlist.com/hostslist/hosts.txt | grep -v "#" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $3}' | grep -v '^\\' | grep -v '\\$' | sort >> $tmp_list

sed -i 's/^ *//; s/ *$//; /^$/d' $tmp_list

Desired output:

address=/0koryu0.easter.ne.jp/0.0.0.0
address=/109-204-26-16.netconnexion.managedbroadband.co.uk/0.0.0.0
address=/11.lamarianella.info/0.0.0.0

Note: 0.0.0.0 can be also some other IP address such as 192.168.1.1.

Input text:

0koryu0.easter.ne.jp
109-204-26-16.netconnexion.managedbroadband.co.uk
11.lamarianella.info
1866809.securefastserver.com
2amsports.com
3.bluepointmortgage.com

Output text:

/10.0.0.1109-204-26-16.netconnexion.managedbroadband.co.uk
/10.0.0.111.lamarianella.info
/10.0.0.11866809.securefastserver.com
/10.0.0.12amsports.com
/10.0.0.13.bluepointmortgage.com
  • Your question isn't at all clear to me, but you seem to have at least two classic issues (1) trying to use / in your pattern or replacement text when sed is already using it as a delimiter: here you need to either escape it \/ or switch to a different delimiter e.g. 's;^;address=/;' (2) expecting variable expansion to occur within single quotes 's/$/$pixelserv_ip/' (switch to double quotes). – steeldriver Oct 30 '16 at 18:51
0

Use sed grouping.

curl -s http://www.malwaredomainlist.com/hostslist/hosts.txt | sed 's#^\([0-9.]*\)  \([a-z0-9.]*\)#address=/\2/0.0.0.0#'

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.