Find the answer to your Linux question:
Results 1 to 10 of 10
I have an script that is taking an input of file and makes it look like: Code: * R###### Main 1.0.0.1 Active Some of the Backup Sets have not run ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75

    Repeating information from one line down until match is made on the next line

    I have an script that is taking an input of file and makes it look like:

    Code:
    *       R######    Main    1.0.0.1         Active          Some of the Backup Sets have not run since Oct 6, 2006
                                                     *      Path\To\Backup A:        Oct 20, 2007    Successful
                                                             Path\To\Backup B:   Oct 17, 2007    Successful
                                                             Path\to\Backup C:      Oct 19, 2007    Successful
                                                             Path\to\Backup D:          Oct 19, 2007    Successful
                                                     *      Path\To\Backup E:        Oct 6, 2007    Successful
    
       R######    Main    1.0.0.1         Active          Some of the Backup Sets have not run since Oct 25, 2006
                                                     *      Path\To\Backup A:        Oct 20, 2007    Successful
                                                             Path\To\Backup B:   Oct 17, 2007    Successful
    
    ...etc
    I am trying to make that R###### appear on everyline. Since there is multiple of these sections and the line count varies I was trying a sed script to do what I wanted. But it is not working.

    Here is what I did

    Code:
    /^\R[0-9]*/,/^\R[0-9]*/{
            s/^R[0-9]*/&/g
    }
    Output I want:

    Code:
    R00001    Main    1.0.0.1         Active          Some of the Backup Sets have not run since Oct 6, 2006
                                                 R00001  Path\To\Backup A: 
                                                 R00001  Path\To\Backup B: 
                                                 R00001  Path\to\Backup C:
                                                 R00001  Path\to\Backup D:
                                                 R00001  Path\To\Backup E:
    R00003    Main    1.0.0.1         Active          Some of the Backup Sets have not run since Oct 25, 2006
                                                 R00003  Path\To\Backup A:       
                                                 R00003  Path\To\Backup B:

    Sadly that is not doing anything. I tried multiple other things. What am I doing wrong.

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    i can't see how you get R00001 and R00003. anyway, its best also to give a sample of that input file

  3. #3
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    The R##### in the output file is an account number that is in the report allready. The first one is a sample of the excat file.

  4. #4
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Code:
    awk '$2 ~ /R[0-9]/ { $1=""; p = $2 }
    $2 !~ /R[0-9]/ {
    	sub( /\*/, "" )
    	$0 = sprintf( "\t\t\t%s %s %s\n", p, $1, $2 )
    }1' filename
    If the input file is different than the one posted above,
    the code should be modified.
    Last edited by radoulov; 10-31-2007 at 11:30 AM. Reason: changed ...

  5. #5
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    Some times the Path\To\Backup A: will have spaces in it. like: To\Backup for A: wtih some info\user

    They can be long but that is the only thing on that line.. I only need up to that the \user anything after that can be removed.

  6. #6
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Quote Originally Posted by Korelis View Post
    Some times the Path\To\Backup A: will have spaces in it. like: To\Backup for A: wtih some info\user

    They can be long but that is the only thing on that line.. I only need up to that the \user anything after that can be removed.
    Please post a sample input/output that includes the fields you mentioned.

  7. #7
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    Code:
    *      R0000001    Main    1.0.0.1         Active          Some of the Backup Sets have not run since Oct 10, 2007
                                                     *       COMPUTER01\Backup of files on D$\administrator       Oct 10, 2007    Successful
                                                     *       SERVER01\Backup of files on P$\administrator        Oct 10, 2007    With Errors (26)
                                                     *       CLINET01\Backup of System State and Services Database\administrator       Oct 10, 2007    Successful
    Some times they are longer then that.

    In the script you posted up what does this do:

    Code:
    	sub( /\*/, "" )
    Is it looking for the star? Because I can strip the stars out. I don't care what it looks like I would prefer it look like something:

    Code:
    R0000001 COMPUTER01\Backup of files on D$\administrator
    R0000001 SERVER01\Backup of files on P$\administrator
    R0000001 CLINET01\Backup of System State and Services Database\administrator
    
    R0000002 COMPUTER01\Backup of files on D$\administrator
    R0000002 SERVER01\Backup of files on P$\administrator
    R0000002 CLINET01\Backup of System State and Services Database\administrator

  8. #8
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    I can run the report using tab to separate everything so -F"\t" could be used if that would help any.

  9. #9
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    Through the joys of what I have learned here I have made some changes to the output of the file to be a little more friendly I believe.

    Code:
            R0000001    Main    1.0.0.1 Active  No Backup Sets have run:
                                                            SERVER\Exchange Server 2007\administrator     Oct 29, 2007    Successful
                                                            SERVER\SQL Server MIP\backup_admin    Oct 29, 2007    Successful
                                                            SERVER\SQL Server CAUW001\backup_admin Oct 29, 2007    Successful
                                                            SERVER\System State and Services Database\backup_admin     Oct 29, 2007    Successful
                                                            SERVER\Test\backup_admin      Oct 29, 2007    Successful
                                                            SERVER\System State and Services Database\backup_admin        Oct 29, 2007    Successful
    
            R0000002    Main    1.0.0.1 Active  No Backup Sets have run:
                                                            SERVER\Backup of Microsoft Exchange Server\backup_admin Oct 25, 2007    Successful
                                                            SERVER\Backup of files on E$,System State and Services Database\backup_admin    Oct 25, 2007
    Hopefully this will make writing the part of the R# all the way down easier. So that it will look like my previous post. While I am waiting for help I am trying to find out the solution using what radoulov has posted earlier. I want to see if what he comes up with works the same way I am able if I can.

  10. #10
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    I got it! I made it work. I got the information I want and now all I have to do is format it.

Posting Permissions

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