Find the answer to your Linux question:
Results 1 to 2 of 2

Thread: awk help needed

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    awk help needed

    Hi, I'm trying to extract the sender id from a fairly large number of files and am having trouble assigning variables from a file. Here is what I have so far, (which is fairly kludgy I know, but it's been some years since I've done any scripting or programming, and I find that I have lost the knack to a large degree).

    grep -r "LOCAL(sdubois)" /var/CommuniGate/SystemLogs/2010-11-16* > test

    awk -f sender test > test2

    sed 's/re-enqueue//' test2 | sed 's/record//' > test3

    sort test3 | uniq > test4

    more sender
    BEGIN {
    FS=" "
    { print $4}
    What this does is to grab all lines for user sdubois from all files in the specified directories, strips out the field that I need that has the message number in it, removes the strings "re-enqueue" and "record", sorts the results of that and removes duplicates, and leaves me with the message numbers in file test4.

    I need one more function to go back through those same files and extract the sender for each of those messages from these lines using the message numbers from test4:

    10:50:38.907 2 QUEUE([15425307]) from <>, 11309 bytes

    The 8 digit number in the brackets are the message numbers.

    I feel sure that this whole thing can be done more efficiently than this lame attempt, but any help would be appreciated.

  2. #2
    Actually, I figured out the variable problem myself. If someone could please tell me how to tell this function what file to search in, I'd be good to go. I can't figure out where to put the name of the search path.

    awk '{
    while (getline > 0) {
    {$3==search} search=var
    {print search}
    }' test4

    When I run this, it prints the contents of test 4, same as when I tell it to print var. This makes sense to me, since I told search=var.

    If I add this string at the very end, it starts printing out the contents of those files instead.


    Where should that string go so that the function uses the strings from test4 to search those files?

Posting Permissions

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