I have a file with multiple IP addresses for different websites, however I only want to print out the websites associated with a specific IP and display the website. For example,,/www.extra.com/home.html,2323,oiehfoioi,wopwpwp,/www.yahoo.com/9998,wjeoiwjo,bbdjksbk

All I need is the websites associated with and I've gotten results using awk to print the entire web address and the IP but I would like to remove the IP How can I combine awk and sed to accomplish this?

  • Please edit your question and show us your desired output. What you show aren't valid URLs, do you also want to remove the first /? Also clarify if what you want is to print the second comma-separated field on lines whose first comma-separated field is a specific IP. Finally, it would help if you show us what you've tried.
    – terdon
    Commented Mar 4, 2017 at 17:16

1 Answer 1


It looks like what you want can be stated as "print the 2nd comma-separated field from any lines whose first comma-separated field is". If so, you can use:

awk -F, '$1==""{print $2}' file

On your example, that prints:

$ awk -F, '$1==""{print $2}' file

Of course, that isn't an actual URL. To also remove the leading /, you can use:

$ awk -F, '$1==""{print $2}' file | sed 's#^/##'

You must log in to answer this question.

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