File manipulation

Legends,

Please help me to get the following
I have a file abc.txt with the following contents

12
13
14
15

And, i want to get the output to a variable like below

12,13,14,15 .... 

How do i do this?

Regards,
san

 tr '\n' ',' < abc.txt

vgersh99

it's working but in the output, it's trimming the command prompt as well

Example:

san% cat /tmp/abc.txt| tr '\n' ','
12,13,14,15,san%

Then use this:

paste -sd, infile

---------- Post updated at 03:06 PM ---------- Previous update was at 03:04 PM ----------

Actually, if you want to assign that string to a variable, the trailing newline shouldn't matter.

1 Like

@radoulov
Thanks, it worked like exactly i wanted. :slight_smile:

$ awk -vORS=" " {print} ORS="," file