0

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?

Paul Kole
  • 3
  • 2

3 Answers3

0

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.

lsd
  • 1,673
  • 10
  • 10
0

An ugly solution:

find . -name '*.txt' | { xargs -n 1 -I_ bash -c 'iconv -f UTF-16 _;echo '; }| ...other-commands...
Mircea Vutcovici
  • 17,619
  • 4
  • 56
  • 83
  • 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
0

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: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

Ole Tange
  • 2,946
  • 6
  • 32
  • 47