LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-04-2010, 04:36 PM   #1
exxoid
LQ Newbie
 
Registered: Mar 2009
Location: Vancouver
Posts: 8

Rep: Reputation: 0
Question Using cut & grep to take out data...


I have a bunch of log files in a directory, and only want to export specific information to a CSV. how can i do this?

The file log.txt log1.txt and log2.txt all contain:

2 Servers, 146 Users (145 Local, 1 Remote, 28 Batch), 3 Apws
03/04/10 Activity: Summary
07:05:03 03/04/10 07:00 to 03/04/10 07:05 (5 min 0 sec)
Buffer pool hit rate: 99 %
03/04/10 Activity: Performance Indicators
07:05:02 03/04/10 07:00 to 03/04/10 07:05 (5 min 0 sec)
Hit Ratio: 99 %
03/04/10 Activity: Buffer Cache
07:05:02 03/04/10 07:00 to 03/04/10 07:05 (5 min 0 sec)

I have managed to get this far...

cat *.txt | grep "5 min" -C 1 | cut -c1-8

But i get...

07:05:03
07:05:03
07:05:03

Now, I only want the 3rd line's date of every log.txt file in my directory to go into output, how can I do this?

Right now it checks every log, and looks for anything "5 min", which there are multiples of..

Is there a way to tell grep to only grep out the "5 min" line once per file?

Thanks.
 
Old 03-04-2010, 04:50 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
I'm not sure about what you're trying to obtain (please post an example of the desired output), anyway the answer to your question is option -m:
Code:
grep -m1 "5 min" *.txt
will retrieve only the first matching line from each file.
 
Old 03-05-2010, 10:18 AM   #3
exxoid
LQ Newbie
 
Registered: Mar 2009
Location: Vancouver
Posts: 8

Original Poster
Rep: Reputation: 0
Each text file contains the data below in a directory, but with different time-stamp and different numbers.

What I want to do is extract the date & numbers in a CSV file so that I can export it into like an Excel document to graph...

I am trying to find a way to extract the [07:05:00] date data from every file (just once, as you can see its there in 2 places) in the directory to another file.

I got this working for the [Record Reads 16081939] entry below, just grabbing the value part with:

cat *.txt | grep "Record Reads" | head -12 | cut -d " " -f9

My output would be something like..

16081939
{data from 2nd text file}
{data from 3nd text file}

How do I do this for the date data on the 3rd row below?

Thanks.

2 Servers, 149 Users (148 Local, 1 Remote, 28 Batch), 3 Apws
03/05/10 Activity: Summary
07:05:00 03/05/10 07:00 to 03/05/10 07:05 (5 min 0 sec)

Event Total Per Sec |Event Total Per Sec

Commits 19921 66.4 |DB Reads 141147 470.5
Undos 75 0.2 |DB Writes 3349 11.2
Record Reads 16081939 53606.5 |BI Reads 22 0.1
Record Updates 16755 55.9 |BI Writes 1154 3.8
Record Creates 2363 7.9 |AI Writes 1080 3.6
Record Deletes 1623 5.4 |Checkpoints 1 0.0
Record Locks 144069 480.2 |Flushed at chkpt 0 0.0
Record Waits 0 0.0

Rec Lock Waits 0 % BI Buf Waits 0 % AI Buf Waits 0 %
Writes by APW 99 % Writes by BIW 65 % Writes by AIW 93 %
DB Size: 18 GB BI Size: 176 MB AI Size: 15 MB
Empty blocks: 80 Free blocks: 369 RM chain: 19
Buffer Hits 99 % Active trans: 16

Buffer pool hit rate: 99 %

03/05/10 Activity: Performance Indicators
07:05:01 03/05/10 07:00 to 03/05/10 07:05 (5 min 0 sec)

Total Per Min Per Sec Per Tx

Commits 19926 3985 66.42 1.00
Undos 75 15 0.25 0.00
Index operations 16117355 3223471 53724.52 808.86
Record operations 16167940 3233588 53893.13 811.40
Total o/s i/o 147050 29410 490.17 7.38
Total o/s reads 141469 28294 471.56 7.10
Total o/s writes 5581 1116 18.60 0.28
Background o/s writes 5528 1106 18.43 0.28
Partial log writes 1229 246 4.10 0.06
Database extends 0 0 0.00 0.00
Total waits 17194 3439 57.31 0.86
Lock waits 0 0 0.00 0.00
Resource waits 17194 3439 57.31 0.86
Hit Ratio: 99 %
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use grep, cut, or awk to get an IP from a file chudster Linux - General 4 02-03-2010 08:06 PM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 08:16 PM
grep and cut command tanveer Linux - General 3 09-05-2008 03:17 AM
cut , paste or grep ziox Programming 1 12-15-2004 11:51 PM
tcprobe+grep+cut Axion Programming 1 08-24-2004 06:27 AM


All times are GMT -5. The time now is 09:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration