Skip to main content
added 276 characters in body
Source Link
rush
  • 28k
  • 9
  • 91
  • 115

It's much easier to use grep for your case. E.g. this way:

grep -o '<a href=[^<]*<\/a>'

In case there are < between <a href>..</a> you might want to try this instead:

grep -o '<a href=.*<\/a>'

However pay attention that it might return a data you don't expect for strings where you have multiple <a href=...</a> occurrences in the same string.

sed doesn't work for you because /pattern1/,/pattern2/p instructs sed to print all lines between line with pattern1 to line with pattern2 (including lines with patterns).

The problem might be solved with sed as well, but it depends on somestupidstuff content (e.g. whether it's the same in all cases or not, etc)

It's much easier to use grep for your case. E.g. this way:

grep -o '<a href=[^<]*<\/a>'

sed doesn't work for you because /pattern1/,/pattern2/p instructs sed to print all lines between line with pattern1 to line with pattern2 (including lines with patterns).

The problem might be solved with sed as well, but it depends on somestupidstuff content (e.g. whether it's the same in all cases or not, etc)

It's much easier to use grep for your case. E.g. this way:

grep -o '<a href=[^<]*<\/a>'

In case there are < between <a href>..</a> you might want to try this instead:

grep -o '<a href=.*<\/a>'

However pay attention that it might return a data you don't expect for strings where you have multiple <a href=...</a> occurrences in the same string.

sed doesn't work for you because /pattern1/,/pattern2/p instructs sed to print all lines between line with pattern1 to line with pattern2 (including lines with patterns).

The problem might be solved with sed as well, but it depends on somestupidstuff content (e.g. whether it's the same in all cases or not, etc)

Source Link
rush
  • 28k
  • 9
  • 91
  • 115

It's much easier to use grep for your case. E.g. this way:

grep -o '<a href=[^<]*<\/a>'

sed doesn't work for you because /pattern1/,/pattern2/p instructs sed to print all lines between line with pattern1 to line with pattern2 (including lines with patterns).

The problem might be solved with sed as well, but it depends on somestupidstuff content (e.g. whether it's the same in all cases or not, etc)