- Community Home
- >
- Servers and Operating Systems
- >
- Legacy
- >
- Operating System - Tru64 Unix
- >
- Re: grep command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2003 02:09 AM
09-07-2003 02:09 AM
I need to extract the pattern from the daily collected file (stat.txt), size 300+MB.
The file contains the following snapshot,
-- Collecting Time at 00:01:02 ----
Data 1 -----------> 1
Data 2 -----------> 5
Data 3 -----------> 7
Data 4 -----------> 2
--TOTAL-----------> 15 ------------
-- Collecting Time at 00:06:02 ----
Data 1 -----------> 1
Data 2 -----------> 15
Data 3 -----------> 7
Data 4 -----------> 2
--TOTAL-----------> 25 ------------
-- Collecting Time at 00:11:02 ----
Data 1 -----------> 3
Data 2 -----------> 5
Data 3 -----------> 7
Data 4 -----------> 12
--TOTAL-----------> 27 ------------
. . .
-- Collecting Time at 23:59:02 ----
Data 1 -----------> 10
Data 2 -----------> 9
Data 3 -----------> 7
Data 4 -----------> 4
--TOTAL-----------> 30 ------------
I need to extract the pattern for only certian period, at about 00:0x:xx and the last line of that particular snapshot, for instance, like following,
-- Collecting Time at 00:01:02 ----
--TOTAL-----------> 15 ------------
-- Collecting Time at 00:06:02 ----
--TOTAL-----------> 25 ------------
-- Collecting Time at 00:11:02 ----
--TOTAL-----------> 27 ------------
I have been tried to use grep command as follows,
. grep -E 'Collecting Time at 00 | TOTAL' stat.txt |tee 0000.lst
. grep -E "Collecting Time at 00 | TOTAL" stat.txt |tee 0000.lst
. egrep -e 'Collecting Time at 00 | TOTAL' stat.txt |tee 0000.lst
. egrep -e "Collecting Time at 00" -e "TOTAL" stat.txt |tee 0000.lst
. . .
And the all output was end up as follows, not exactly I need,
--TOTAL-----------> 15 ------------
--TOTAL-----------> 25 ------------
--TOTAL-----------> 27 ------------
Any idea would help.
Soontorn
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2003 10:51 PM
09-07-2003 10:51 PM
Re: grep command
Is there also a space before the TOTAL?
If so, then my advice should solve it.
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2003 10:58 PM
09-07-2003 10:58 PM
Re: grep command
I found that when run the above grep commands I have following output,
. . .
--TOTAL-----------> xx ------------
--TOTAL-----------> xx ------------
--TOTAL-----------> xx ------------
-- Collecting Time at 00:01:02 ----
--TOTAL-----------> 15 ------------
-- Collecting Time at 00:06:02 ----
--TOTAL-----------> 25 ------------
-- Collecting Time at 00:11:02 ----
--TOTAL-----------> 27 ------------
. . .
--TOTAL-----------> xx ------------
--TOTAL-----------> xx ------------
--TOTAL-----------> xx ------------
--TOTAL-----------> xx ------------
. . .
--TOTAL-----------> 30 ------------
--TOTAL-----------> xx ------------
--TOTAL-----------> xx ------------
--TOTAL-----------> xx ------------
. . .
Question: how to remove the TOTAL xx or TOTAL that is not associated to the selected period by grep command.
Regards
Soontorn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2003 11:35 PM
09-07-2003 11:35 PM
Re: grep command
grep -E 'Collecting Time at 00|TOTAL.*[0-9][0-9]' stat.txt
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2003 10:23 PM
09-08-2003 10:23 PM
Re: grep command
Let me add some more I have a script running to collect the statistics for every interval, 1 - 600 second for example.
Every interval the script put the snapshot into the file, stat.txt and a snapshot looks like follow,
-- Collecting Time at 00:01:02 ----
Data 1 -----------> 1
Data 2 -----------> 5
Data 3 -----------> 7
Data 4 -----------> 2
--TOTAL-----------> 15 ------------
There are four data, (1,5,7,2), and the total is 15. And I need to remove the details of data1, data2, data3, and data4, save only first line and last line in hourly, for example I'd like to save the collected time and TOTAL value which generated during midnight of the day.
I wondering the grep command would enough to be used in this case.
Regards,
Soontorn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2003 12:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2003 01:11 AM
09-09-2003 01:11 AM
Re: grep command
You can't do this with grep alone.
grep is doing exactly what you ask it to do. This means, it shows you all lines containing the string "TOTAL" --or-- the string "Collecting Time at 00"
That's why you see the lines with "TOTAL .." at the end of your output.
Following script is not the shortest, but looks quite simple. (ksh is needed)
grep -e "Collecting Time at 00" -e "TOTAL" stat.txt > tempfile.lst
LAST=`grep -n "Collecting Time" tempfile.lst | tail -1 | cut -d ":" -f 1`
let LAST=LAST+1
head -n ${LAST} < tempfile.lst > 0000.lst
rm tempfile.lst
Enjoy
Joris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2003 08:38 PM
09-10-2003 08:38 PM
Re: grep command
you get the idea):
clipper V5.1> cat prog
input_time=$1
data=$2
awk -v time="$input_time" '
{
if($0 ~ /TOTAL/) { NR=0 }
if(NR == 1 && $5 == time) {
prt="true"
}
if(/TOTAL/ && prt=="true") {
prt="false"
}
}' $data
Here's the test:
clipper V5.1> prog "00:01:02" data
-- Collecting Time at 00:01:02 ----
--TOTAL-----------> 15 ------------
clipper V5.1> prog "00:06:02" data
-- Collecting Time at 00:06:02 ----
--TOTAL-----------> 25 ------------
clipper V5.1> prog "00:11:02" data
-- Collecting Time at 00:11:02 ----
--TOTAL-----------> 27 ------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2003 09:56 PM
09-10-2003 09:56 PM
Re: grep command
I got the point grep can't use alone to retrieve the result as needed but need other tools to formulate a script, thanks for kindly help.
Regards,
Soontorn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2003 08:55 PM
09-12-2003 08:55 PM
Re: grep command
$ awk '/at 00:0/{x=1;print}/TOTAL/{if (x){x=0;print}}' < your-file.data
In words: if you see a line with 'at 00:0' set flag x and print the line. If you see a line with 'TOTAL' and flag x is set, clear flag x and print it, if flag x was not set, meaning you there was no recent 00:0x line, then just ignore the total line.
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2004 05:12 AM
03-22-2004 05:12 AM