Skip to main content
3 of 3
edited tags; bash is not a text editor
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

Extracting Multiple Strings in a Single Line, Between Two Types of Characters

I have file consisting of a single line of text. I am trying to obtain the strings between the "#" and "@" symbols and store them as a newline on "Sequence.txt".

For example, I have the input line:

#HelloMyName@#IsAdam@#NiceToMeetYou@

The expected output should be:

HelloMyName
IsAdam
NiceToMeetYou

I have tried the command: following line of code:

sed 's/.*#\(.*\)@.*/\1/' >> Sequence.txt

However, the output is exactly the input:

#HelloMyName@#IsAdam@#NiceToMeetYou@