1833873 Members
3197 Online
110063 Solutions
New Discussion

Re: scripting

 
SOLVED
Go to solution

scripting

Hi,
If I have a file called file1 with the contents as follows:

line1
line2
line2

Is it possible to run a script to append the data from file1 into file2 in the following format:

line1,line2,line3

Thanks in advance,
Trystan.
10 REPLIES 10
T G Manikandan
Honored Contributor

Re: scripting

#paste file1 file2 >file3
john korterman
Honored Contributor
Solution

Re: scripting

Hi Trystan,
you could do something like this:
cat file1 | tr "\012" ","

regards,
John K.
it would be nice if you always got a second chance
Ramkumar Devanathan
Honored Contributor

Re: scripting

hi Trystan,

$ echo `cat file1`

- ramd.
HPE Software Rocks!
James R. Ferguson
Acclaimed Contributor

Re: scripting

Hi Trystan:

Another way:

# xargs < filename

Regards!

...JRF...

Re: scripting

Thanks all for your help. This is now working.
Regards,
Trystan.
Jean-Luc Oudart
Honored Contributor

Re: scripting

If you want the comma at the right place

echo `cat file1` | sed -e 's/ /,/g'

JL
fiat lux
Ramkumar Devanathan
Honored Contributor

Re: scripting

Trystan, i read your post wrong. Sorry for the mispost.

here's another way -

awk '{printf ("%s, ",$0}' file1

- ramd.
HPE Software Rocks!
H.Merijn Brand (procura
Honored Contributor

Re: scripting

# perl -nle'push@x,$_}END{print join",",@x' file1 >>file2

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Robin Wakefield
Honored Contributor

Re: scripting

YES!!, I beat Merijn for perl code length:

perl -la0ne'print join",",@F' file1 > file2

rgds, Robin...
H.Merijn Brand (procura
Honored Contributor

Re: scripting

Robin, congrat :)

Shall we start an obfuscation contest?

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn