to append data in a single row

Hi all,

I need a logic in UNIX to append contents of a file in same row, where the original contents are found one below the other. For example.

My i/p file contains:
�user1�,�employee1�,�04/28/2009�
�5678�
�78�
�user2�,�employee2�,�04/30/2009�

I want my output as
�user1�,�employee1�,�04/28/2009�,�5678�,�78�,�user2�,�employee2�,�04/30/2009�

Please look at the comma between each entry. Each value should be delimited by comma.

Regards Meera

Code:

cat file | tr '\n' ',' >> file1

$ cat file
"user1","employee1","04/28/2009"
"5678"
"78"
"user2","employee2","04/30/2009"

$ cat file1
"user1","employee1","04/28/2009","5678","78","user2","employee2","04/30/2009"

Does this help?

Cheers,
Sai

cat a.txt | tr "\n" ","

/usr/xpg4/bin/awk '/04\/30\/2009/{print;next}NF{printf("%s ",$0)}' $file

here 04/30/2009 is the end of your file

hi sai...im getting the o/p as follows..

�user1�,�employee1�,�04/28/2009�,�5678�,�78�,�user2�,�employee2�,�04/30/2009�,,

there are two commas at the end..i dont need comma after the last entry. can you please help me with this?

I think that you have two empty lines at the end of your original file, get rid of them

Try this. This is probably because you have an empty line in the file.

sed '/^$/d file | tr '\n' ',' >> file1

cheers,
Devaraj Takhellambam

hi all,
thanks a lot...the above command works fine...as per my requirement i need to append these to the next line after the occurence of last number or character in a file. whats the grep command to search for the last occurence of a charater or number in a file and start off with the next entry in the new line following the last leter or number?

tr "\n" ","