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/$/\/' > $tmp_list_final
  2. Running the line below gives the output text mentioned.

    sed -i 's/.*/address=&\/' $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:


Note: can be also some other IP address such as

Input text:


Output text:

  • 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

Use sed grouping.

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

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.