AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
#Power
#Operatingsystems
#Servers
 View Only
  • 1.  Need help...

    Posted 11/05/07 09:42 AM

    Originally posted by: SystemAdmin


    Hello guys,

    I have a file called "myFile.log" , the file contains system logs with the dates...Now...I want my script
    to open up the file and search for a specific date for example (05-11-2007) and when it find the date, copies the rest of file into
    another file. Here is an example

    MYFile.log contains:
    <hr />
    scripts running on suday
    Script running on monday
    .
    .
    Script running on 05-11-200
    Testing
    testing
    <hr />

    Now I want to create a newFile which contains only

    <hr />
    Script running on 05-11-200
    Testing
    testing
    <hr />

    Not sure if my question is clear enough or not...plz let me know so I can explain it more.
    #AIX-Forum


  • 2.  Re: Need help...

    Posted 11/05/07 10:28 AM

    Originally posted by: SystemAdmin


    Something like the following:

    grep -q "11-05-2007" myFile.log && cp myFile.log some.other.file

    should do what you're looking for.

    HTH

    Jim Lane
    #AIX-Forum


  • 3.  Re: Need help...

    Posted 11/05/07 10:36 AM

    Originally posted by: SystemAdmin


    But this just cp myFile to another file. What I want is to look for the date and if it finds it then copy the REST(start point would be the date) of the file to another file. plz look at my example.
    #AIX-Forum


  • 4.  Re: Need help...

    Posted 11/05/07 05:05 PM

    Originally posted by: SystemAdmin


    Try the csplit command....

    $ csplit MYFile.log %05-11-200%

    This will create a file named xx00 which contains:
    $ cat xx00
    Script running on 05-11-200
    Testing
    testing
    You might want to look at the other options to csplit:
    http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.cmds/doc/aixcmds1/csplit.htm
    #AIX-Forum


  • 5.  Re: Need help...

    Posted 11/06/07 09:46 AM

    Originally posted by: SystemAdmin


    Thanks a million
    #AIX-Forum