2

The following command prints 3 lines:

echo -e 'a\nb\nc'

result:

a  
b  
c  

How can I achieve the above result when passing from xargs?

echo 'a\nb\nc' | xargs -I{} echo -e {}

Current result:

anbnc

3 Answers 3

1

Add a \ to explicit the use of \n:

echo 'a\\nb\\nc' | xargs -I{} echo -e {}

Result:

a
b
c
1

Correct answer: ( Posted by a user and then removed)

Use a delimiter (-d)

echo 'a\nb\nc' | xargs -d '\n' -I{} echo -e {}

Result:

a
b
c
-1

Have you tried correcting

echo 'a\n\b\n\c'

to

echo 'a\nb\nc'

The output is on different lines then. Is that what you want?

1
  • the command as it is in your question is generating the expected output in my sh. Is it still anbnc for you?
    – ruud
    May 27, 2020 at 13:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .