Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to join output of the xargs output by new lines. I do this:

find . -name '*.txt' | xargs -n 1 iconv -f UTF-16 | ...other-commands...

I take one file at a time and convert it to UTF-8 (the system locale). All of the *.txt are one-liners without newline character at the end. So the output of xargs is a mess of text.

How do you separate items of xargs output by \n?

share|improve this question
up vote 0 down vote accepted

An ugly solution:

find . -name '*.txt' | { xargs -n 1 -I_ bash -c 'iconv -f UTF-16 _;echo '; }| ...other-commands...
share|improve this answer
Ok, thank you. It works just fine. find . -name '*.txt' | {xargs -n 1 -I% bash -c 'iconv -f UTF-16 %; echo;'} – Paul Kole Feb 11 '13 at 18:56

You could try:

find . -name '*.txt' | (xargs -n 1 iconv -f UTF-16; echo; ) | ...other-commands...

That should add a newline after the output of xargs, before piping to the other commands.

share|improve this answer
Sorry, it doesn't work like this. – Paul Kole Feb 11 '13 at 18:47
Ah I see where I went wrong. ( created a subshell, { would probably have worked (like the other answer). – lsd Feb 11 '13 at 19:45

Using GNU Parallel you could have done:

find . -name '*.txt' | parallel -k "iconv -f UTF-16 {}; echo" | ...other-commands...

As an added bonus the iconvs would run in parallel.

Watch the intro videos to learn more:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.