Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

3 Answers 3

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
add comment

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

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.