Pulling info from various files

Discussion in 'General Linux' started by jaluht, Nov 6, 2012.

  1. jaluht

    jaluht New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi, Im new to linux so please excuse any ignorance.

    I have a folder with 562 log files. The log files contain info with a trace count which keeps increasing by 1 until approximately 22,000. What i need to do is search each file in the folder and pull out the file name and the final trace count. Is there any way this can be done without pulling the previous 21,999 trace counts in each file?

  2. Rob

    Rob Administrator Staff Member

    Messages:
    575
    Likes Received:
    217
    Trophy Points:
    43
    So you need to cat the last line of each one, then print a few parts of it?

    Code:
    for x in $(tail -n 1 /folder/*.log); do cat $x | awk '{print $2, $5}';done
    So, if this works ... :)

    Breaking it down:

    Code:
    tail -n 1
    will print the last line of a file

    Code:
    cat $x | awk 'print $2, $5}'
    will take the line and print the 2nd and 5th fields (using space as separator).
  3. jaluht

    jaluht New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Its not the last line though, ex.

    seg fault
    seg fault
    trace count 1
    ...
    trace count 22000
    seg fault
    seg fault
    etc
  4. Rob

    Rob Administrator Staff Member

    Messages:
    575
    Likes Received:
    217
    Trophy Points:
    43
    How about..

    Code:
    for x in $(grep 'trace count' /folder/*.log|tail -n 1); do cat $x | awk '{print $2, $5}';done
    ?
  5. Rob

    Rob Administrator Staff Member

    Messages:
    575
    Likes Received:
    217
    Trophy Points:
    43
    Or - if the lines are that short and there's no need to awk things out of it..

    Code:
    grep 'trace count' /folder/*.log| tail -n 1
    (maybe)
  6. jaluht

    jaluht New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    syntax error near unexpected token ' ( '
  7. jaluht

    jaluht New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    This did nothing? Each file has approx 160,000 lines
  8. Rob

    Rob Administrator Staff Member

    Messages:
    575
    Likes Received:
    217
    Trophy Points:
    43
    My syntax is probably wrong then - try looking into cat/grep/tail, etc..

Share This Page