Add few characters

Hello,

I have a file with few n number of lines .I want to add any character ie comma "," in begining of each line of the file i dont know how many lines the file may contain Also, i want to add comma twice ot thrice in front of each line like 3 coulmn's.

input file

abc
def
ijk

output file
,,,abc
,,,def
,,,ijk

i tried the same via apaste command but not giving me desried input...

Pls suggest some online command for the same....

Thanks in advance

Aparna

If you have Perl... .

$ cat x.dat
abc
def
ijk
$ perl -p -i -e "s/^/,,,/g" x.dat
$ cat x.dat
,,,abc
,,,def
,,,ijk
$

Dear Nathan,

I looked at your solution. You used 3 flags with perl, can you please tell me what they are for?

regards
Apoorva Kumar

Hello,

i dont have perl on my sun machine .... pls suggest within shells....

regards,

Hi,

you can also try this

cat file | sed 's/^/,,,/' > newfile
mv newfile file

regards
Apoorva Kumar

thanks a lot for such a good and quick suggestion...

Regards,

This is an explanation of the command line flags I used above.

'-i' edits files in place.
'-e' allows you to define Perl code to be executed
'-p' loops around every line in the file and performs the substitution

Something like this?

filename a.awk

BEGIN {
        RS=""
}
{
for (i=1;i<=NF;i++)
        {
        array=$i
        }
}
END {
        for (k=1;k<=i-1;k++)
        {
                for (j=0;j<=i-2;j++)
                {
                printf ",";
                }
        print array[k];
        }
}
awk -f a.awk data 

hth