facha
facha

Reputation: 12522

bash: read stdin line by line with custom line delimiter

I have a bash script that reads lines from stdin.

while read var
do
    echo $var
done

Now, I have to modify this so I could accept input with line delimiter "EndOfMessage" (delimiter of several symbols).

How could I do that?

Upvotes: 0

Views: 2045

Answers (1)

Gordon Davisson
Gordon Davisson

Reputation: 125788

If I understand this right, the input will be something like "line1EndOfMessageline2EndOfMessageline3"? If so, you can do it like this:

sed $'s/EndOfMessage/\\\n/g' | while read var; do
    echo $var
done

Upvotes: 1

Related Questions