Pulling data and following lines from file


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pulling data and following lines from file
# 1  
Pulling data and following lines from file

I saw a few posts close to what i want to do, but they didn't look like they would work exactly.. or I need to think out of the box on this.

I have a file that I keep server stats in for my own performance analysis. this file has the output from many commands in it (uptime, vmstats, ps, swap space) . I have since rewritten my monitoring, but now I need to go back and pull only the vmstats and its response out of my files for 2004.

I wrote a script that can walk through the file one line at a time and look for the value vmstat and pull out the date in the following line (see below file excerpt) but I can' t figure out how to tell the script to pull the lines with the actual data. I really only want the cpu idle column with a date in my output:
Example, I want my output to be:

2004.07.01[00:04:03] 42
2004.07.01[00:04:03] 48

etc.


my input file excerpt:


Unix Uptime
2004.07.01[00:04:03]

00:04 up 4 days, 11:49, 34 users, load average: 22.66, 25.20, 25.54

vmstat 2 5
2004.07.01[00:04:03]

Virtual Memory Statistics: (pagesize = 8192)
procs memory pages intr cpu
r w u act free wire fault cow zero react pin pout in sy cs us sy id
33 849 38 278K 34K 200K 96M 16M 47M 3M 17M 457K 665 9K 8K 42 18 40
29 854 38 280K 33K 200K 6112 657 3917 0 617 0 595122K 10K 48 52 0
36 847 37 279K 34K 200K 4380 145 3598 0 112 0 687 77K 10K 55 45 0
28 857 39 279K 34K 200K 2310 447 1325 0 396 0 608 65K 10K 58 42 0
33 852 38 279K 33K 200K 3569 268 2399 0 284 0 611129K 10K 53 47 0

swap space
2004.07.01[00:04:16][/FONT]
# 2  
This works for me... Note that the first line of output would be the average CPU idle time since last reboot. If you want user or system space CPU usage, change $18 to $16 or $17 to grab the field you want.
Code:
$ cat ./input.awk
#! /usr/bin/awk -f

/vmstat/ {
   getline
   datestamp = $0
}

/r w u act/ {
  { while ( $0 !~ /^$/ ) {
      getline
      if ( $0 != "" ) {
        printf( "%s %s\n", datestamp, $18 )
      }
    }
  }
}
$ cat ./input
Unix Uptime
2004.07.01[00:04:03]

00:04 up 4 days, 11:49, 34 users, load average: 22.66, 25.20, 25.54

vmstat 2 5
2004.07.01[00:04:03]

Virtual Memory Statistics: (pagesize = 8192)
procs memory pages intr cpu
r w u act free wire fault cow zero react pin pout in sy cs us sy id
33 849 38 278K 34K 200K 96M 16M 47M 3M 17M 457K 665 9K 8K 42 18 40
29 854 38 280K 33K 200K 6112 657 3917 0 617 0 595 122K 10K 48 52 0
36 847 37 279K 34K 200K 4380 145 3598 0 112 0 687 77K 10K 55 45 0
28 857 39 279K 34K 200K 2310 447 1325 0 396 0 608 65K 10K 58 42 0
33 852 38 279K 33K 200K 3569 268 2399 0 284 0 611 129K 10K 53 47 0

swap space
2004.07.01[00:04:16]
$ ./input.awk input
2004.07.01[00:04:03] 40
2004.07.01[00:04:03] 0
2004.07.01[00:04:03] 0
2004.07.01[00:04:03] 0
2004.07.01[00:04:03] 0
$

Cheers
ZB
# 3  
Glad you reminded me to skip the first line too. !!

thanks!
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #107
Difficulty: Easy
Each Unix kernel subsystem has key features like concurrency, virtual memory, paging, and a virtual file system.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pulling information from a data file by date

awk -v now="$(date +%s)" -v tDiff="${USERMINUTES}" ' BEGIN { FS="=" if (!now) now=systime() if (!tDiff) tDiff=60*60 p=1 } /{/ {rec=$0;p=1;next} /}/ && rec && p {print rec ORS $0;next} $1=="entry_time" { if (now-$2>tDiff)p=0 } {rec=rec ORS $0}'... (6 Replies)
Discussion started by: SkySmart
6 Replies

2. Shell Programming and Scripting

Pulling Data, Then Moving to the Next File

I'm scanning a list of emails- I need to pull 2 pieces of data, then move to the next file: Sender's Email Address Email Date I need these to be outputted into a single column- separated by a ",". Like this: Email1's Address, Email1's Date Stamp Email2's Address, Email2's Date Stamp... (4 Replies)
Discussion started by: sudo
4 Replies

3. Shell Programming and Scripting

BASH- Need help pulling data from .emlx

Hello, fellow computer junkies. First time poster! My boss wrote an application (Mavericks 10.9, Mountain Lion 10.8) that checks a user's security settings. The user runs the application, then it spits out an email that is sent back to our inbox showing the results. On our end, we have a mail rule... (5 Replies)
Discussion started by: sudo
5 Replies

4. Shell Programming and Scripting

Pulling data from xml

Hi there, Please could anyone help with this. I have an xml file that contains repeating values eg <Rule name> AAAAA <Action> BBBBB </Action> <Data> CCCCC </Data> <Type> DDDDD </Type> </Rule name> <Rule name> A1A1A1A1 <Action> B1B1B1B1 </Action> <Data> C1C1C1C </Data> <Type>... (4 Replies)
Discussion started by: ssideel
4 Replies

5. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

6. Shell Programming and Scripting

Pulling x number of lines from one file and save into another

Hi, I have a log file (updates.log), and I want to hunt the file for any errors. Here's an example of the log file: SQL> update <table1> set <value1> = '*****'; update <table1> set <value1> = '*****' * ERROR at line 1: ORA-00942: table or view does not exist Elapsed:... (4 Replies)
Discussion started by: dbchud
4 Replies

7. Shell Programming and Scripting

Pulling data by GPS coordinates from text file

Hi there, I'm having a problem trying to extract data from within a text file. I'm trying to extract this manually for a lack of better words. I need any items that fall within latitude 36.5 to 39.5 and long -75.3 to -83.9 I have been doing this using cat neta.txt | grep '!38' and working... (6 Replies)
Discussion started by: Mikey
6 Replies

8. Shell Programming and Scripting

Help with pulling / filtering data from a .csv

Good day Gurus, I have a csv file that contains an inventory of active servers. This csv file contains a well over a hundred systems (IBM, SUN, HP). It also contains those systems details. See below for an example hostA,invver,1.02,20100430 hostA,date,08/30/2010,06:18 hostA,use,"Unknown... (4 Replies)
Discussion started by: LuffyDMonkey
4 Replies

9. Shell Programming and Scripting

SFTP to server, pulling data and removing the data

Hi all, I have the following script, but are not too sure about the syntax to complete the script. In essence, the script must connect to a SFTP server at a client site with username and password located in a file on my server. Then change to the appropriate directory. Pull the data to the... (1 Reply)
Discussion started by: codenjanod
1 Replies

10. Shell Programming and Scripting

Pulling multiple lines of text

Hello, So, I'm not even sure if this will be possible for me to do (then again, that's why I'm asking for help ;) ) What I'm trying to do is pull multiple lines out of a very large text file, separating them into smaller files. Basically it's a text archive of a few hundred emails. What I... (2 Replies)
Discussion started by: DumDum
2 Replies

Featured Tech Videos