I am trying to work with a text file named itemlist.txt that contains:
http://example.com/item-a
http://example.com/item-b
http://example.com/item-c
http://example.com/item-d
http://example.com/item-e
I've tried many different variations of code. Some will return just the item but not the url. I can't figure out how to assign $url correctly. This is about the closest I've come to achieving the desired output.
#!/bin/bash
while read url; do
for item in $(sed "s/http:\/\/example.com\///g"); do
echo $item $url; done
done < itemlist.txt
The desired output is:
item-a http://example.com/item-a
item-b http://example.com/item-b
item-c http://example.com/item-c
item-d http://example.com/item-d
item-e http://example.com/item-e
But instead I am getting:
item-b http://example.com/item-a
item-c http://example.com/item-a
item-d http://example.com/item-a
item-e http://example.com/item-a
Can someone shed some light on how to do this correctly?