Find the answer to your Linux question:
Results 1 to 5 of 5
I have the following text (see attachment) What I need to do is select the entire line that matches a variable in this case SQL-2005-UserDB What I need to do ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    5

    AWK Challenge

    I have the following text (see attachment)

    What I need to do is select the entire line that matches a variable in this case SQL-2005-UserDB

    What I need to do is select only the entries with a SQL-2005-UserDB and only the line that that is the oldest of that day.

    I need the full line like

    iqn.2001-05.com.equallogic:0-8a0906-ff1ca4602-834f35dc31c47b72-sql-2005-userdb-2008-02-16-13:48:17.115

    I would like to use AWK..most of my other parsing is being done by awk where I have my AWK code in another file and I am calling the file using AWk -f file > another file.

    I need help created in file with the code that will do what I need. I am struggling with the best way to accomplish this.
    Attached Files Attached Files

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I need help created in file with the code that will do what I need. I am struggling with the best way to accomplish this.
    Struggle is good. It builds character.

    Why don't you show us the awk script you have so far, so we can help you fix it?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    5
    Well I do not have much of the AWK code. What I have been playing with is something like

    AWK /SQL-2005-UserDB/ { print } filename

    But i beleive running that will give me all the SQL-2005-UserDB lines which is more than one. I need to single out only the SQL-2005 that was run on the same date as the script was run then select (somehow) the last one in the list by time.

    If I capture the current date of the system and save that into a variable then pass that varialble into my AWK command? So SQL-2005-UserDB(Variable) so now it looks like SQL-2005-UserDB-2008-02-16- Now the challenge is to pick the latest time in the list.

    One thing that might help is that the hour will always be 23.

    Can I search for all SQL-2005-UserDB-date then search for only the ones who have 23 on the hour filed then print the entire line?

  4. #4
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    i gave a suggestion here. see if it suit your needs. Also, look at other suggestions.

  5. #5
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    The nice thing about posting a problem on just one site is that if someone provides a solution, then others who see that solution won't bother to do the duplicate work. But if it's known that you're posting on, say, n sites, then you might have n people come up with a workable solution, wasting the time of n-1 of them. The idea is not pleasant.

    I glance at the data you provide and notice that the one with the most recent time for a given date isn't necessarily the one for that date which is the closest to the end of the file. This means that sorting must be done, unless you're absolutely sure that the required entry is at 23:00:00 or later, and is the only such entry.

    In either case, the solution is obvious, but I'll leave it to the guys on unix.com to spell it out, test it, and post it.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

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