Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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 have file:

xxx.lst

with values:

111
222
333

I just need to make one line with:

111 222 333

into a variable or standard output.

share|improve this question
up vote 7 down vote accepted

paste is probably the best tool for this job:

$ paste -sd ' ' file
111 222 333
share|improve this answer
    
Awesome, didn't even know this exists, even on AIX :-). Thx. – user165435 yesterday
    
@user165435: It works in any POSIX compliant system. – cuonglm yesterday
    
Nice, I looked it up, paste belongs to coreutils package – warl0ck 16 hours ago
    
@warl0ck: It's POSIX standard, too. – cuonglm 16 hours ago

You can use tr to replace line separator with space, e.g

set -f
somevar="$(tr '\n' ' ' < xxx.lst)"
echo $somevar
share|improve this answer
    
works of course – user165435 yesterday

Xargs echo and i/o redirection.

xargs echo < xxx.lst

You don't even need the echo.

xargs < xxx.lst

Tested on ksh/aix and bash/GNU.

share|improve this answer
    
Note that xargs choked on unbalance double quotes line, remove balance double quotes line. – cuonglm yesterday
    
True! xargs -0 < xxx.lst with GNU xargs will work with any unbalanced quote marks. – bgStack15 yesterday

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.