-1

I want to cut out extra words without losing the ranges that follow emxaple :

int.domain.com<BR>stage.domain.com<BR>helth.domain.com

I want to remove it <BR>

Without losing it The two domains that follow

stage.domain.com
helth.domain.com

I want to do that by using the grep tool

And thanks

abdallaEG
  • 103
  • 1
  • 6

2 Answers2

1

Using sed

sed 's#<BR>#\n#g' 

Demo:

:=>echo "int.domain.com<BR>stage.domain.com<BR>helth.domain.com"  | sed 's#<BR>#\n#g' 
int.domain.com
stage.domain.com
helth.domain.com
:=>

Digvijay S
  • 2,665
  • 1
  • 9
  • 21
  • This answer is wrong, partially but still. Sed will not always substitute with `'\n'` - in cygwin/mingw for example, and more importantly how are you going to remove first domain from output as this was in a question? – tansy Mar 18 '20 at 10:03
0

You can't use grep alone to do that. Grep only searches patterns not substitutes them.

$ echo "int.domain.com<BR>stage.domain.com<BR>helth.domain.com" | awk 'BEGIN{FS="<BR>"} { for (i=2; i<=NF; i++) print $i }'
stage.domain.com
helth.domain.com

FS is field separator, then print all from 2'nd element.

tansy
  • 486
  • 3
  • 8
  • Or just …`awk 1 RS='
    |\n'`, RS is the record separator, so tell awk you have records separated by `
    ` or newlines
    – jthill Mar 18 '20 at 03:49
  • I tried that and it didn't work. Don't know where exactly is a catch here. It's not going to work as you wrote it - whole script must be in between `' '`. – tansy Mar 18 '20 at 10:11
  • mmm, I assumed GNU's awk, which handles regex record separators fine, I'd tested before commenting. – jthill Mar 18 '20 at 16:56