3

This code should read from wget2.html and output the links found. But it gives me output without line breaks. How can I force cat to add line breaks?

chksitename=$(cat wget2.html | grep -e "$sitename" | sed -e "s/^.*\("$sitename".*jpg\).*$/\1/g" | sort | uniq)
echo $chksitename
Jonathan Leffler
  • 698,132
  • 130
  • 858
  • 1,229
Crazy_Bash
  • 1,625
  • 8
  • 26
  • 38

3 Answers3

15

The problem is not in the cat line but in the echo line. To get the line breaks, you need to use:

echo "$chksitename"

See also Capturing Multiple Line Output to a Bash Variable.

Community
  • 1
  • 1
Jonathan Leffler
  • 698,132
  • 130
  • 858
  • 1,229
1

I think you can replace your cat/grep/sed with one sed:

sed -e -n "/$sitename/ s@^.*\("$sitename".*jpg\).*$@\1@pg" wget.html

And you can replace sort | uniq to sort -u.

uzsolt
  • 5,450
  • 2
  • 18
  • 31
0

You could try:

echo $chksitename | tr ' ' '\n'
Mat
  • 195,986
  • 40
  • 382
  • 396