Script to copy specific data.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to copy specific data.
# 1  
Old 12-16-2010
Script to copy specific data.

Hi,

I have written a shell script which monitors my application and generates a report. The out put of the same looks like this.


PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
30700 xmp 15 0 2986m 2.9g 1488 S 0.0 18.3 66:00.93 cee

This report is generated every 2 mins in a different file. I want to generate a report which will grep the above content and generate a new file( may be an xls) which can help me to get th graph.

Regards,
Siddhesh.K
# 2  
Old 12-16-2010
Whats the issue your facing? Post few contents of the file.
Code:
grep -A1 '^PID .*' inputfile

# 3  
Old 12-16-2010
Hi,

I am not able to grep the relevant contents to a new file.

The file contains followng data.

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

30700 xmp 15 0 2986m 2.9g 1488 S 0.0 18.3 66:00.93 cee


I want only thePID, CPU and MEM to be grepped to new file

Regards,
Siddhesh.K
# 4  
Old 12-16-2010
Code:
 
awk '{print $1,$9,$10}' inputFile > newFile

# 5  
Old 12-16-2010
cut -d" " -f1,9,10 inputfile > newfile
R0H0N
# 6  
Old 12-16-2010
Hi,

Thanks anurag. but the input file has other details too whic are also being printed. I only want the cpu mem and pid, nothing else

##############

top users, load
Tasks: stopped, 0
Cpu(s): id, 0.1%
Mem: buffers
Swap: cached

PID %CPU %MEM
30700 0.0 18.3

Thanks,
Sid
# 7  
Old 12-16-2010
Code:
awk '{if(a=="PID")print $1,$9,$10;a=$1;}' inputFile > newFile

OR more specific checks
Code:
awk '{if(a=="PID" && b=="%CPU" && c=="%MEM")print $1,$9,$10;a=$1;b=$9;c=$10;}' inputFile > newFile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy Specific Files Recursively

Is it possible to only copy selected files+its directories when you are copying recursively? find /OriginalFolder/* -type -d \{ -mtime 1 -o -mtime 2 \ } -exec cp -R {} /CopyTo/'hostname'__CopyTo/ \; -print From the above line, I want to only copy *txt and *ini files from /OriginalFolder/* ... (4 Replies)
Discussion started by: apacheLinux
4 Replies

2. Shell Programming and Scripting

How to copy a directory without specific files?

Hi I need to copy a huge directory with thousands of files onto another directory but without *.WMV files (and without *.wmv - perhaps we need to use *.). Pls advise how can I do that. Thanks (17 Replies)
Discussion started by: reddyr
17 Replies

3. Shell Programming and Scripting

Converting text files to xls through awk script for specific data format

Dear Friends, I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls. The input is as follows: >gi|1234|ref| Query = 1 - 65, Target = 1677 - 1733 Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46 fd sdfsdfsdfsdf fsdfdsfdfdfdfdfdf... (6 Replies)
Discussion started by: Amit1
6 Replies

4. Shell Programming and Scripting

KSH Script -- loop and data copy question

I am trying to write a script that will allow me to train others with commands that I run manually by only allowing the exact command before continuing onto the next set of commands. Here is where I come into an issue. I have changed the directories for this post. Software we run creates files... (2 Replies)
Discussion started by: hurtzdonut
2 Replies

5. Shell Programming and Scripting

Shell script to find specific file name and load data

I need help as to how to write a script in Unix for the following: We have 3 servers; The mainframe will FTP them to a folder. In that folder we will need the script to look and see if the specific file name is there and load it to the correct table. Can anyone pls help me out with... (2 Replies)
Discussion started by: msrahman
2 Replies

6. Shell Programming and Scripting

Need help in writing a script to create a new text file with specific data from existing two files

Hi, I have two text files. Need to create a third text file extracting specific data from first two existing files.. Text File 1: Format contains: SQL*Loader: Release 10.2.0.1.0 - Production on Wed Aug 4 21:06:34 2010 some text ............so on...and somwhere text like: Record 1:... (1 Reply)
Discussion started by: shashi143ibm
1 Replies

7. Shell Programming and Scripting

How to copy specific file.txt in specific folder?

hye there... i have a problem to copy file in specific folder that will change the name according to host,time(%m%s) and date(%Y%M%D) example folder name: host_20100531.154101801 this folder name will always change... but i just want to copy the AAA.txt and BBB.txt file.. really need... (17 Replies)
Discussion started by: annetote
17 Replies

8. Shell Programming and Scripting

Korn/bash Script to monitor a file a check for specific data

Hi, Im trying to write this script but im stuck on it, basicaly what i want to do is to write a code to verify a log file ( apache log file for example ) and for each new line with specific data , then, output this new line for another file: full ex: output of the server.log is (... (4 Replies)
Discussion started by: Thales.Claro
4 Replies

9. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

10. Shell Programming and Scripting

Sample ksh script for copy the data from excel to database table ?

Hi All, I need to convert the data from excel to database table in sybase. Please provide some sample script.. thanks, Royal. (1 Reply)
Discussion started by: royal9482
1 Replies
Login or Register to Ask a Question