0

It is maybe a noob question but i cannot find an answer. How can i use SED to find Santa83_4. The name Santa83_4 is an example and can be anything with any charcater.

....\randomtext\randomtext\name\Santa83_4\rate\randomtext\randomtext...

Thanks is advance

  • this appears to have been covered in another topic? http://stackoverflow.com/questions/13242469/how-to-use-sed-grep-to-extract-text-between-two-words – jimmy8ball Apr 10 '17 at 12:35
  • I know that topic, and played with it. It did not give me the answer i need. – W H Hermans Apr 10 '17 at 12:41
  • Why? I mean why bother trying to find "foo" using "sed" on a string so you can print "foo" when you could just do `echo "foo"` if all you want is a tool that outputs "foo". What are you REALLY trying to do? – Ed Morton Apr 11 '17 at 02:35

1 Answers1

0

grep approach:

s='...\randomtext\randomtext\name\Santa83_4\rate\randomtext\randomtext..'
echo $s | grep -Po '\\name\\\K[^\\]+'

sed approach:

echo $s | sed -n 's/.*\\name\\\([^\\]*\).*/\1/p'

The output(for both approaches):

Santa83_4
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105