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

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

improved formatting
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175

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

For example, I have the input line: #HelloMyName@#IsAdam@#NiceToMeetYou@ The

#HelloMyName@#IsAdam@#NiceToMeetYou@

The expected output should be: HelloMyName IsAdam NiceToMeetYou

HelloMyName
IsAdam
NiceToMeetYou

I have tried the command: following line of code: sed 's/.#(.)@.*/\1/' >> Sequence.txt

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

However, the output is exactly the input: #HelloMyName@#IsAdam@#NiceToMeetYou@

#HelloMyName@#IsAdam@#NiceToMeetYou@

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@

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@
Source Link

BASH: 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@