alex
alex

Reputation: 45

Force printing on new line in bash in a while loop when using 2 commands

I've been trawling the web and I can't seem a way force a second command to print on a new line in a while loop, using bash. Here's an example file:

$ cat testing
foo
bar
testing
hello

Here's an example loop:

$ cat testing | while read line; do echo -e $line, $(echo $line); done
foo, foo
bar, bar
testing, testing
hello, hello

I'd like to loop to print everything on a new line, like:

foo
foo
bar
bar
testing
testing
hello
hello

I'd like this to include for if the output for the second command, the one in brackets, has more than one interation as an output, to also print this on a new line.

Thanks,

Upvotes: 0

Views: 1662

Answers (2)

karakfa
karakfa

Reputation: 67467

Or the awk version

awk '1;1'

prints each line twice.

Upvotes: 0

tripleee
tripleee

Reputation: 189327

Like this?

while read -r line; do echo "$line"; echo "$line"; done <testing

or even

sed p testing

Upvotes: 1

Related Questions