2

I have many web addresses which are including some special interface names, which I would like to remove. Examples:

aaaaaaa-INT1.aaaa.aaaa.com
bbbbbbb-INT2.bbbb.bbbb.com
ccccccc-INT.cccc.cccc.com

So my expected result after sed should be:

aaaaaaa.aaaa.aaaa.com
bbbbbbb.bbbb.bbbb.com
ccccccc.cccc.cccc.com

I have tried this, but it doesnt work:

sed 's/-.*^.//'

Any suggestion please?

Alex
  • 47
  • 5
  • see also: https://stackoverflow.com/questions/5319840/greedy-vs-reluctant-vs-possessive-quantifiers and https://stackoverflow.com/questions/43650926/how-to-match-a-specified-pattern-with-multiple-possibilities – Sundeep May 11 '18 at 09:25

2 Answers2

4

To remove the first dash and everything before the first period:

$ sed 's/-[^.]*//' file
aaaaaaa.aaaa.aaaa.com
bbbbbbb.bbbb.bbbb.com
ccccccc.cccc.cccc.com
James Brown
  • 36,089
  • 7
  • 43
  • 59
1

Solution 1st: Following sed may help you on same too.

sed 's/\([^-]*\)-\([^.]*\)\(.*\)/\1\3/'  Input_file

Solution 2nd: With awk.

awk -F"." '{sub(/-.*/,"",$1)} 1' OFS="."   Input_file
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93