Operating System - HP-UX
1753797 Members
7359 Online
108799 Solutions
New Discussion юеВ

Need a script to get the words in one line

 
SOLVED
Go to solution
Roopesh Francis_1
Trusted Contributor

Need a script to get the words in one line

Hi experts,

Could you please somebody help me to get a script to make the file as below.
my input file is like below
#cat file
word1
word2
word3
word4
I need this file as below
#cat file
word1 word2 word3 word4

Appreciate all your help!!

Thanks,
Roopesh
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: Need a script to get the words in one line

Hi:

One way is :

# echo $(
Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Need a script to get the words in one line

Hi (again):

Another (common) solution is to use 'tr' as:

# tr "\012" " " < file

Regards!

...JRF...
Raj D.
Honored Contributor
Solution

Re: Need a script to get the words in one line

Roopesh,

# cat file1 | xargs

Cheers,
Have fun!,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: Need a script to get the words in one line

Also: # cat file | tr "\n" " " ; printf "\n"
" If u think u can , If u think u cannot , - You are always Right . "
Roopesh Francis_1
Trusted Contributor

Re: Need a script to get the words in one line

Hi James/RAj,

cat file|xargs is working fine.

Thank you very much for your quick response.

Cheers,
Roopesh
Roopesh Francis_1
Trusted Contributor

Re: Need a script to get the words in one line

Issue is resolved
James R. Ferguson
Acclaimed Contributor

Re: Need a script to get the words in one line

Hi (again):

If you like the:

# cat file1 | xargs

...do yourself and your server a favor: save a process and eliminate the 'cat':

# xargs < file1

Regards!

...JRF...
Roopesh Francis_1
Trusted Contributor

Re: Need a script to get the words in one line

Hi JRF,

Thanks for the suggestion.i will do
echo $(
Thanks,
Roopesh