0

In one of my use case, required to trim the needed prefix by using below sed command. just curious to know is there any way to reduce the sed command (i mean simpler way instead of having long trim :) )

Actual content:

example1-m.uk.db.com

Required output:

example1

My sed command:

echo example1-m.uk.db.com | sed 's/[A-Z]*\-[a-z]\.[a-z]*[0-9]*\.[a-z]*[0-9]*\.[a-z]*//'

This gives me as output:

example1

Thank you.

Cheers , Velu

Paolo
  • 21,270
  • 6
  • 38
  • 69
Velu
  • 23
  • 4
  • 1
    `sed 's/-.*//'`? If you need to remove all after the first `-` it will work. A similar solution: `awk -F'-' '{print $1}'`. What are your actual requirements? If we suggest something too simplified, it won't work with other strings you might have. – Wiktor Stribiżew Aug 03 '18 at 12:08
  • @WiktorStribiżew super, thank you very much. :) ah got that awk , cheers. my requirement is simple with my use case just extract the output and refer this on other invoking script. executed successfully with my sed command, however your suggestion fits easier and quick. thanks again. – Velu Aug 03 '18 at 12:10

0 Answers0