unix shell script which inserts some records into a file located in remote servers...

All, I need to write an unix shell script which inserts some records into a file located in remote servers.

  • Get the input from the user and insert according the first row. It should be in ascending order.
    123451,XA,ABA
    123452,XB,ABB
    123453,XC,ABC
    123455,XE,ABE
    123456,XF,ABF
    123458,XG,ABG

Now I would like to insert these records "123454,XY,ABD", "123457,XZ,ABZ". I need output like below (ie, file needs to get updated like this)

123451,XA,ABA
123452,XB,ABB
123453,XC,ABC
123454,XY,ABD -- First Record
123455,XE,ABE
123456,XF,ABF
123457,XZ,ABZ -- Second Record
123458,XG,ABG

I need to update the same in different servers at the same time (ie. when I run this script). I'm new to unix shell scripting and now I'm learning.

Can someone help me out with this...many thanks in advance~!

If the file is sorted in numeric order by the first column you can do something like:

echo "$string" >> file    # append string to the file
sort -n file > newfile    # sort file and redirect output to newfile
mv newfile file           # move newfile to file

Regards

Thanks Franklin, actually I have three fields however I need sort the file based on first column but meanwhile I would like insert the row at last.

For example,

Existing file..

001,a,aaa
002,b,asdewr
002,b,asdaas
002,c,sader
003,r,asdsa
004,l,asdhjie
005,kalsdka

I need to inser these records now...(as per your code, its perfect)

002,c,asdasd

but I also need the output like this:

001,a,aaa
002,b,asdewr
002,b,asdaas
002,c,sader
002,c,asdasd
003,r,asdsa
004,l,asdhjie
005,kalsdka

Please help me...thanks much in advance!

AND Also I need to update the same file (located) in different servers at the same time