Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 20
Hello Everyone, I have a little more complex question then I did last time. What I am trying to do is write a shell script that will enable me to ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75

    bash script to search and write a few things.

    Hello Everyone,

    I have a little more complex question then I did last time. What I am trying to do is write a shell script that will enable me to do a few things. Maybe this not the place to pose this question but I would like to get some feed back.

    I have a script that is working quite well. But I need to take on some more automation from my end to change things to make it easier. My question is this. In the sample line below is there an easy way to make the date from the number format into the word day format and remove the time. To explain more what I am doing the line starts out in a TAB separated document. I then use sed to strip out all the special characters and switch things (document has / and then /* and $) around and of course sorting the file. So here is what the line looks like when I first get it.

    Code:
    ACC####	R#####	Backup	A\PATH\username 10/18/07 8:00:10 PM
    Everything is tab separated except there is a space after the date and time.

    Using that line above (which is currently tab separated) is take that date from 10/18/07 to the actual day name. Here is what I want the line to look like afterwards

    Code:
    ACC####	R#####	Backup	A\PATH\backup_admin	Thursday
    Very easily I am not sure if I can do that without getting into something a little more advanced then the shell script.

    Now my next question. This will not apply to the sample line above. Is it possible to grep for a certain text and grab everything until you hit an blank empty line? I am going to grep for a few words and then under that there will be various amounts of lines under that text if it shows up. If it does I want to be able to grab everything under that line and the next empty would make it move on to the next text that matches what I grep for.

  2. #2
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    Okay I found what I was looking for in the first list. Now my question is can I some how search of a string of text an have it stop after it reaches a new string?

  3. #3
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    With awk:
    Code:
    awk 'f&&/new string/{print;exit};/string/{f=1}f' filename

  4. #4
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    I maybe should have stated this earlier. Is there a way to have it do this throught the entire file. There will be multiple instances in the file and I want to capture the string that it finds grab that string and then everything before the new string.

  5. #5
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    If you post a samle input file and the desired output,
    it would be easier.

  6. #6
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    Quote Originally Posted by radoulov View Post
    If you post a samle input file and the desired output,
    it would be easier.
    Basically I am pulling a report of backups. In this report (which is being done very poorly mind you) there is a string that will say some of these backup sets have not run since (DATE)


    Code:
    Customer Name: 	 Customer 1
    Customer Backup Status Summary: 	 All of these Sys-Clients have performed backups
     	 Sys-Client # 	 Location 	 Version 	 Status 	 Sys-Client Backup Status Summary 	  	 Backup Set 	 Last Backup 	 Sys-Client Backup Status Summary 
       	 R###### 	 Main 	 1.0.0.1 	 Active 	 All Backup Sets have run
     	 	 	 	 	 	 * 	 Path\to\backup 	 Oct 17, 2007 	 With Errors (1)
    Customer Name: 	Customer 2
    Customer Backup Status Summary: 	 All of these Sys-Clients have performed backups
     	 Sys-Client # 	 Location 	 Version 	 Status 	 Sys-Client Backup Status Summary 	  	 Backup Set 	 Last Backup 	 Sys-Client Backup Status Summary 
       	 R###### 	 Main 	 1.0.0.1 	 Active 	 All Backup Sets have run
     	 	 	 	 	 	  	 Path\to\backup 	 Oct 17, 2007 	 Successful
     	 	 	 	 	 	 * 	 Path\To\backup 
    ustomer Name: 	 Customer 3
    Customer Backup Status Summary: 	 Some of these Sys-Clients have not performed backups
     	 Sys-Client # 	 Location 	 Version 	 Status 	 Sys-Client Backup Status Summary 	  	 Backup Set 	 Last Backup 	 Sys-Client Backup Status Summary 
     * 	 R###### 	 Main 	 1.0.0.1 	 Active 	 Some of the Backup Sets have not run since Oct 16, 2007
     	 	 	 	 	 	  	 Path\to\Backup 	 Oct 17, 2007 	 Successful
     	 	 	 	 	 	 * 	 Path\to\Backup 	 Oct 16, 2007 	 Successful
    What I would like to see is anything in the file that shows that the backup set did not run in a file. I want the lines to show me below that string of text I am finding. Using the script you gave me here is what I did.

    Code:
     
    awk 'f&&/Customer/{print;exit};/Some of the Backup Sets have not run/{f=1}f' status
    Which did what I wanted it to. But I am going to have several lines in the entire file reporting that same find string (Some backup sets have not run) and I want to stop when it sees the next customer unless that customer matches the backup set have not run string.

    Thank you for your help on this as well. Can I ask what the f&& does in the awk command?

  7. #7
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    If that's what you want,
    you could write it like this:
    Code:
    awk '/not run/,/^Customer/' status
    But may be this is better:

    Code:
    awk '/^Customer/{f=0};/not run/{f=1}f' status

  8. #8
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    That works out. That second line does a better trick for me. I now need to figure out how I can remove the lines that the date is either Equal to the day or one day before the current date but anything over 2 days is still displayed.

    Is this possible to do in shell or do I need to look at using something like perl?

  9. #9
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Could you post sample input(including unwanted records) and output?

  10. #10
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    Hello,

    Yes I can and thank you for your continued response on this. I am trying to understand the lines you are providing to know how they work and so I can do more of this on my own.

    Output after running the command you gave. Please note that the first * should be ignored as it changes based on if the backup ran and if so did it have errors when it last ran.

    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
    Now using this example above here is what I need to know. Today is Oct. 20, 2007. The data I do not need in there is the lines that have the date which is older then the 24 hours. So above I need the lines that the date does not match Oct 20, 2007 and/or Oct 19, 2007.

Page 1 of 2 1 2 LastLast

Posting Permissions

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