how to omit data from a file created in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to omit data from a file created in a script
# 1  
Old 07-07-2009
Bug how to omit data from a file created in a script

I am using the fallowing script. this script seems to work fine except the file has data I do not wish to have. Is there away to omit that data. I will first provide the scrip and then a sample of the data the way it looks and then a sample of how I would like the data to look. Thanks for any help. I am very new to UNIX and scripting as well.

This is the script I am using

#!/bash
sar -u 1 1 >>/home/scripts/cpu.$(date +"%Y.%m.%d").csv
swapinfo >>/home/scripts/memory.$(date +"%Y.%m.%d").csv


This is how the file looks now
HP-UX commnms B.11.11 U 9000/800 07/07/09

08:35:00 %usr %sys %wio %idle
08:35:01 65 35 0 0

HP-UX commnms B.11.11 U 9000/800 07/07/09

08:40:00 %usr %sys %wio %idle
08:40:01 58 42 0 0

HP-UX commnms B.11.11 U 9000/800 07/07/09

08:45:00 %usr %sys %wio %idle
08:45:01 24 24 51 1

Here is how I would like the file to look
HP-UX commnms B.11.11 U 9000/800 07/07/09

08:35:00 %usr %sys %wio %idle
08:35:01 65 35 0 0
08:40:01 58 42 0 0
08:45:01 24 24 51 1

I would then like to import the file in to Microsoft excel for some data manipulation. I suppose I could just email the file to me then copy and past it into excel.

This is on a HPUX box
# 2  
Old 07-07-2009
Add these following lines to your script and try:

grep HP-UX /home/scripts/memory.*.csv | uniq
grep '%idle' /home/scripts/memory.*.csv| head -1
grep -v ^$ /home/scripts/memory.*.csv| grep -v HP-UX | grep -v '%idle'
# 3  
Old 07-07-2009
Quote:
Originally Posted by guruprasadpr
Add these following lines to your script and try:

grep HP-UX /home/scripts/memory.*.csv | uniq
grep '%idle' /home/scripts/memory.*.csv| head -1
grep -v ^$ /home/scripts/memory.*.csv| grep -v HP-UX | grep -v '%idle'
Dose the placement of these lines matter? Do they go before or after the sar command?
# 4  
Old 07-12-2009
Sorry for the late reply. These lines go after the swapinfo command.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to check current date file is created and with >0 kb or not for multiple directories

Hi All, I am new in scripting and working in a project where we have RSyslog servers over CentOS v7 and more than 200 network devices are sending logs to each RSyslog servers. For each network devices individual folders create on the name of the each network devices IP addresses.The main... (7 Replies)
Discussion started by: Pinaki
7 Replies

2. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

3. Shell Programming and Scripting

Join files, omit duplicated records from one file

Hello I have 2 files, eg more file1 file2 :::::::::::::: file1 :::::::::::::: 1 fromfile1 2 fromfile1 3 fromfile1 4 fromfile1 5 fromfile1 6 fromfile1 7 fromfile1 :::::::::::::: file2 :::::::::::::: 3 fromfile2 5 fromfile2 (4 Replies)
Discussion started by: CHoggarth
4 Replies

4. Shell Programming and Scripting

Shell script replied multiple process for file has successfully created

Hi All, I have written the following code do FILE_NO=$(echo $LINE|awk -F"|" '{print $1}'|tr "'" '+'|sed 's/\(.*\)\(++\)\(.*\)\(++\)/\3/') INST_NO=$(echo $LINE|awk -F"|" '{print $2}'|tr "'" '+'|sed 's/\(.*\)\(++\)\(.*\)\(++\)/\3/') if ] then ... (3 Replies)
Discussion started by: yogendra.barode
3 Replies

5. Shell Programming and Scripting

Combine/omit data from 2 files

i made a script on my own. this is for the inventory to all of my AWS servers, and i run it to all of my servers to get the hostname, please look at file2. Then i need some data in file3 as well,. i need to combine them #cat file1 192.10.1.41 server.age.com ###### 192.10.0.40 ssh cant... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

6. Shell Programming and Scripting

awk command to omit trailer record in a file

I am trying to omit the trailer record in a variable width file I tried using awk 'NR >1 { print prev } { prev = $0 }' filename The above command is giving output but somehow it is trimming columns from the record. For example if my record has columns A,B,C,D The awk gives output as A,B,C ... (4 Replies)
Discussion started by: abhilashnair
4 Replies

7. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

8. UNIX for Dummies Questions & Answers

How to get data only inside polygon created by points which is part of whole data from file?

hiii, Help me out..i have a huge set of data stored in a file.This file has has 2 columns which is latitude & longitude of a region. Now i have a program which asks for the number of points & based on this number it asks the user to enter that latitude & longitude values which are in the same... (7 Replies)
Discussion started by: reva
7 Replies

9. Shell Programming and Scripting

AWK script to omit top characters with dashes

Hi I have an AWK script that takes an input file and outputs it as CSV format. The problem is its also outputting the characters at the top which are dashes(-------) and i want it to leave them out. My script is as follows. BEGIN { count=1; } /^/ { count+=1 if ( count > 2 ){... (3 Replies)
Discussion started by: magikminox
3 Replies

10. Shell Programming and Scripting

Loop through files in dir, omit file with latest date

I want to loop through files in a directory but omit the file with the latest date in my list of files. How would I accomplish this? Thanks (2 Replies)
Discussion started by: stringzz
2 Replies
Login or Register to Ask a Question