Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2007
    Posts
    1

    Unanswered: Fomart input file and ftp to 3 different servers

    Need help on a script to perform the following actions:

    I have a text file (records.txt) generated from one server (Server_A), this file is delimited by semicolon (. It contains details which should be ftp to other 3 servers to be used as an input file to a script which will then process the files. Field 5 of records.txt contains the name of the server to be sent the file. So there has to be three new text files generated from records.txt depending on server name. The first task is to replace the semicolon in records.txt with space. Example of records.txt is below:

    records.txt
    03/03/07;40065;MER11;40000;STR_SERV2;1;0.00;23.83;10:00: 00;0.00;23.45;FAULTY_UNIT
    03/03/07;40065;MER11;40000;STR_SERV1;1;0.00;23.83;10:00: 00;0.00;23.45;RESTORED
    03/03/07;40065;MER11;40000;STR_SERV3;1;0.00;23.83;10:00: 00;0.00;23.45;FAULTY_UNIT
    03/03/07;40065;MER11;40000;STR_SERV1;1;0.00;23.83;10:00: 00;0.00;23.45;FAULTY_UNIT
    03/03/07;40065;MER11;40000;STR_SERV1;1;0.00;23.83;10:00: 00;0.00;23.45;RESTORED
    03/03/07;40065;MER11;40000;STR_SERV2;1;0.00;23.83;10:00: 00;0.00;23.45;FAULTY_UNIT
    03/03/07;40065;MER11;40000;STR_SERV1;1;0.00;23.83;10:00: 00;0.00;23.45;FAULTY_UNIT
    03/03/07;40065;MER11;40000;STR_SERV1;1;0.00;23.83;10:00: 00;0.00;23.45;RESTORED
    03/03/07;40065;MER11;40000;STR_SERV2;1;0.00;23.83;10:00: 00;0.00;23.45;FAULTY_UNIT
    03/03/07;40065;MER11;40000;STR_SERV1;1;0.00;23.83;10:00: 00;0.00;23.45;FAULTY_UNIT
    03/03/07;40065;MER11;40000;STR_SERV3;1;0.00;23.83;10:00: 00;0.00;23.45;RESTORED

    The above file should generate 3 files (STR_SERV1.txt, STR_SERV2.txt & STR_SERV3.txt) to be ftp to the 3 servers

    STR_SERV1.txt (FTP to STR_SERV1)
    03/03/07 40065 MER11 40000 STR_SERV1 1 0.00 23.83 10:00:00 0.00 23.45 RESTORED
    03/03/07 40065 MER11 40000 STR_SERV1 1 0.00 23.83 10:00:00 0.00 23.45 FAULTY_UNIT
    03/03/07 40065 MER11 40000 STR_SERV1 1 0.00 23.83 10:00:00 0.00 23.45 RESTORED
    03/03/07 40065 MER11 40000 STR_SERV1 1 0.00 23.83 10:00:00 0.00 23.45 FAULTY_UNIT
    03/03/07 40065 MER11 40000 STR_SERV1 1 0.00 23.83 10:00:00 0.00 23.45 RESTORED
    03/03/07 40065 MER11 40000 STR_SERV1 1 0.00 23.83 10:00:00 0.00 23.45 FAULTY_UNIT

    STR_SERV2.txt (FTP to STR_SERV2)
    03/03/07 40065 MER11 40000 STR_SERV2 1 0.00 23.83 10:00:00 0.00 23.45 FAULTY_UNIT
    03/03/07 40065 MER11 40000 STR_SERV2 1 0.00 23.83 10:00:00 0.00 23.45 FAULTY_UNIT
    03/03/07 40065 MER11 40000 STR_SERV2 1 0.00 23.83 10:00:00 0.00 23.45 FAULTY_UNIT

    STR_SERV3.txt (FTP to STR_SERV3)
    03/03/07 40065 MER11 40000 STR_SERV3 1 0.00 23.83 10:00:00 0.00 23.45 FAULTY_UNIT
    03/03/07 40065 MER11 40000 STR_SERV3 1 0.00 23.83 10:00:00 0.00 23.45 RESTORED

    Thanks for a shell script to perform the function above

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Talking


    Here is a place to start:
    Code:
    sort -t';' -k 5 records.txt|tr ';' ' '|\
    awk '{if ( "$5" != s ) s=$5; print $0 > s".txt"}'

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •