Skip to main content
added 415 characters in body
Source Link
glenn jackman
  • 88.6k
  • 16
  • 124
  • 180

becauseBecause both read and sed are taking data from stdin.

(more details to follow In the while loop, you read the first line into $line. Then sed starts: you don't give it any other input so it reads from stdin, which is the output of cat numbers.txt. So sed will consume the rest of the input.) And since you're still in the first iteration of the while loop, the $line variable doesn't change

I'd use perl for this:

perl -lne '($spaced = $_) =~ s/./$& /g; print qq{<item>$spaced<tag>out="$_"}' numbers.txt

because both read and sed are taking data from stdin.

(more details to follow...)

Because both read and sed are taking data from stdin.

In the while loop, you read the first line into $line. Then sed starts: you don't give it any other input so it reads from stdin, which is the output of cat numbers.txt. So sed will consume the rest of the input. And since you're still in the first iteration of the while loop, the $line variable doesn't change

I'd use perl for this:

perl -lne '($spaced = $_) =~ s/./$& /g; print qq{<item>$spaced<tag>out="$_"}' numbers.txt
Source Link
glenn jackman
  • 88.6k
  • 16
  • 124
  • 180

because both read and sed are taking data from stdin.

(more details to follow...)