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
  • 730,956
  • 141
  • 904
  • 1,278
Crazy_Bash
  • 1,755
  • 10
  • 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
  • 730,956
  • 141
  • 904
  • 1,278
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,832
  • 2
  • 20
  • 32
0

You could try:

echo $chksitename | tr ' ' '\n'
Mat
  • 202,337
  • 40
  • 393
  • 406