Repetitive Tasks


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Repetitive Tasks
# 1  
Old 11-17-2005
Question Repetitive Tasks

Could someone tell me how I can simplify the script that follows!!!
I know that there must be a way how to

grep Average from sar01..................
sar02 .......................
sar03.......................
sar04 and output it to its own file.

My intention is to collect data for the whole month and place in an Excel graph, to monitor how my system worked for the month,



grep Average sar01 > Avgrep01.txt
grep Average sar02 > Avgrep02.txt
grep Average sar03 > Avgrep03.txt
grep Average sar04 > Avgrep04.txt
grep Average sar05 > Avgrep05.txt
grep Average sar06 > Avgrep06.txt
grep Average sar07 > Avgrep07.txt
grep Average sar08 > Avgrep08.txt
grep Average sar09 > Avgrep09.txt
grep Average sar10 > Avgrep10.txt
grep Average sar11 > Avgrep11.txt
grep Average sar12 > Avgrep12.txt
grep Average sar13 > Avgrep13.txt
grep Average sar14 > Avgrep14.txt
grep Average sar15 > Avgrep15.txt
grep Average sar16 > Avgrep16.txt
grep Average sar17 > Avgrep17.txt
grep Average sar18 > Avgrep18.txt
grep Average sar19 > Avgrep19.txt
grep Average sar20 > Avgrep20.txt
grep Average sar21 > Avgrep21.txt
grep Average sar22 > Avgrep22.txt
grep Average sar23 > Avgrep23.txt
grep Average sar24 > Avgrep24.txt
grep Average sar25 > Avgrep25.txt
grep Average sar26 > Avgrep26.txt
grep Average sar27 > Avgrep27.txt
grep Average sar28 > Avgrep28.txt
grep Average sar29 > Avgrep29.txt
grep Average sar30 > Avgrep30.txt
grep Average sar31 > Avgrep31.txt


###########

head -1 Avgrep01.txt > Avhead01.txt
head -1 Avgrep02.txt >> Avhead01.txt
head -1 Avgrep03.txt >> Avhead01.txt
head -1 Avgrep04.txt >> Avhead01.txt
head -1 Avgrep05.txt >> Avhead01.txt
head -1 Avgrep06.txt >> Avhead01.txt
head -1 Avgrep07.txt >> Avhead01.txt
head -1 Avgrep08.txt >> Avhead01.txt
head -1 Avgrep09.txt >> Avhead01.txt
head -1 Avgrep10.txt >> Avhead01.txt
head -1 Avgrep11.txt >> Avhead01.txt
head -1 Avgrep12.txt >> Avhead01.txt
head -1 Avgrep13.txt >> Avhead01.txt
head -1 Avgrep14.txt >> Avhead01.txt
head -1 Avgrep15.txt >> Avhead01.txt
head -1 Avgrep16.txt >> Avhead01.txt
head -1 Avgrep17.txt >> Avhead01.txt
head -1 Avgrep18.txt >> Avhead01.txt
head -1 Avgrep19.txt >> Avhead01.txt
head -1 Avgrep20.txt >> Avhead01.txt
head -1 Avgrep21.txt >> Avhead01.txt
head -1 Avgrep22.txt >> Avhead01.txt
head -1 Avgrep23.txt >> Avhead01.txt
head -1 Avgrep24.txt >> Avhead01.txt
head -1 Avgrep25.txt >> Avhead01.txt
head -1 Avgrep26.txt >> Avhead01.txt
head -1 Avgrep26.txt >> Avhead01.txt
head -1 Avgrep27.txt >> Avhead01.txt
head -1 Avgrep28.txt >> Avhead01.txt
head -1 Avgrep29.txt >> Avhead01.txt
head -1 Avgrep30.txt >> Avhead01.txt
head -1 Avgrep31.txt >> Avhead01.txt


###########


sed '/^$/d' Avhead01.txt | nawk -F " " '{print $2,$3,$4,$5}' > sarcpu_btl-main.txt

###########




head -12 Avgrep01.txt | tail -1 > Avhead02.txt
head -12 Avgrep02.txt | tail -1 >> Avhead02.txt
head -12 Avgrep03.txt | tail -1 >> Avhead02.txt
head -12 Avgrep04.txt | tail -1 >> Avhead02.txt
head -12 Avgrep05.txt | tail -1 >> Avhead02.txt
head -12 Avgrep06.txt | tail -1 >> Avhead02.txt
head -12 Avgrep07.txt | tail -1 >> Avhead02.txt
head -12 Avgrep08.txt | tail -1 >> Avhead02.txt
head -12 Avgrep09.txt | tail -1 >> Avhead02.txt
head -12 Avgrep10.txt | tail -1 >> Avhead02.txt
head -12 Avgrep11.txt | tail -1 >> Avhead02.txt
head -12 Avgrep12.txt | tail -1 >> Avhead02.txt
head -12 Avgrep13.txt | tail -1 >> Avhead02.txt
head -12 Avgrep14.txt | tail -1 >> Avhead02.txt
head -12 Avgrep15.txt | tail -1 >> Avhead02.txt
head -12 Avgrep16.txt | tail -1 >> Avhead02.txt
head -12 Avgrep17.txt | tail -1 >> Avhead02.txt
head -12 Avgrep18.txt | tail -1 >> Avhead02.txt
head -12 Avgrep19.txt | tail -1 >> Avhead02.txt
head -12 Avgrep20.txt | tail -1 >> Avhead02.txt
head -12 Avgrep21.txt | tail -1 >> Avhead02.txt
head -12 Avgrep22.txt | tail -1 >> Avhead02.txt
head -12 Avgrep23.txt | tail -1 >> Avhead02.txt
head -12 Avgrep24.txt | tail -1 >> Avhead02.txt
head -12 Avgrep25.txt | tail -1 >> Avhead02.txt
head -12 Avgrep26.txt | tail -1 >> Avhead02.txt
head -12 Avgrep27.txt | tail -1 >> Avhead02.txt
head -12 Avgrep28.txt | tail -1 >> Avhead02.txt
head -12 Avgrep29.txt | tail -1 >> Avhead02.txt
head -12 Avgrep30.txt | tail -1 >> Avhead02.txt
head -12 Avgrep31.txt | tail -1 >> Avhead02.txt


##########

sed '/^$/d' Avhead02.txt | nawk -F " " '{print $2,$3}' > sarmem_btl-main.txt


##########



rm Av*.txt
# 2  
Old 11-18-2005
Try this.

Code:
#! /bin/ksh

typeset -ZR2 day=1

while (($day <= 31))
do
grep Average sar${day} > Avgrep${day}.txt
day=$(($day+1))
done

sed '/^$/d' Avhead01.txt | nawk -F " " '{print $2,$3,$4,$5}' > sarcpu_btl-main.txt

day=1
while (($day <= 31))
do
head -1 Avgrep${day}.txt >> Avhead01.txt
sed -n -e '12p' Avgrep${day}.txt >> Avhead02.txt
day=$(($day+1))
done

sed '/^$/d' Avhead02.txt | nawk -F " " '{print $2,$3}' > sarmem_btl-main.txt

rm -f Av*.txt

Not tested.

Vino
# 3  
Old 11-18-2005
Repetitive Tasks

Will try and inform if works,

Thanks for your time

Jair
# 4  
Old 11-18-2005
Repetitive Tasks

Thanks man,

I modified it just a little because it was not finding Avhead01.
It was just the position of the sed request.

I then added a couple ftp commands to my laptop.

Grateful,

Jair
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Improving repetitive tasks in function

stop_service () { sudo systemctl is-active --quiet video.service && sudo systemctl stop video.service && sudo rm /etc/systemd/system/video.service && echo stop video sudo systemctl is-active --quiet audio.service && sudo systemctl stop audio.service && sudo rm /etc/systemd/system/audio.service... (4 Replies)
Discussion started by: aristosv
4 Replies

2. Shell Programming and Scripting

awk regexp to print repetitive pattern

How to use regexp to print out repetitive pattern in awk? $ awk '{print $0, "-\t-\t-\t-\t-\t-\t-\t-\t-\t-\t-\t-"}' output: - - - - - - - - - - - -I tried following which does not give what I want, of course. awk '{print $0, "-\t{11}-"}' output: - ... (10 Replies)
Discussion started by: yifangt
10 Replies

3. Shell Programming and Scripting

I need help to removing repetitive lines

Hello SuperUsers! First i wanna say my english sucks.. Don't hate me for that. :rolleyes: I need to make a Bash for removing smilar lines from an output file. My output file always same. Line 1 & 2 Stays. And others similar to this lines needs to be delete. </UsageData><?xml version="1.0"... (4 Replies)
Discussion started by: morphin
4 Replies

4. Shell Programming and Scripting

Repetitive ending of script

Hi, I am quit satisfied with this scrtipt and really don't want to change anything but the end. I get a repetitve option when I want to "quit" and don't know why. What am I missing? When I press q to quit with this script, I get an EXTRA "Enter " How do I correct this so that when I press... (1 Reply)
Discussion started by: jefferj54
1 Replies

5. UNIX for Dummies Questions & Answers

Repetitive scripts within a bash shell

I have a bash shell that even though it does not look pretty is working very well. Some of the steps are repetitive, something like this: muscle -in ${e}.4 > $e.5 read -t1 sed ':a /^>/!N;s/\n\(\)/\1/;ta' $e.5 > $e.6 read -t2 awk '/>/{fr=$3;getline;n=split ($0,a,""); for (i=1;i<=n;i++)... (2 Replies)
Discussion started by: Xterra
2 Replies

6. Shell Programming and Scripting

Print lines between two repetitive patterns

Hi users I have one file which has number of occurrence of one pattern examples Adjustmenttype,11 xyz 10 dwe 9 abd 13 def 14 Adjustmenttype,11 xyz 24 dwe 34 abd 35 def 11 nmb 12 Adjustmenttype, not eleven .... ... ... (2 Replies)
Discussion started by: eranmoh
2 Replies

7. Shell Programming and Scripting

Unix Remove repetitive alphabets

Hi, I am trying to write a script that will take 2 or more instances of repetitive alphabets (ZZ) to be removed from a field. This should only happen from beginning and end of a field. For Example : Input File a) ZZZIBM Corporation b) ZZZIBM Corporation ZZZZZ b) IBM ZZZ... (26 Replies)
Discussion started by: msalam65
26 Replies

8. Shell Programming and Scripting

Perl Repetitive Pattern Matching

Problem: GIVEN ======= my $sql="INSERT INTO table_nm(a, b, b, d, e, f , g) VALUES (2046, TODAY, 'Change Subscription Name', '00000000000002000000000000000000000000000000000000', '00000000000001000000000000000000000000000000000000', '00000000000000000000000000000000000000000000000000', 1);... (2 Replies)
Discussion started by: Niroj
2 Replies

9. Shell Programming and Scripting

Count if numbers are not repetitive

Hi All, I have an input below and i would want to do a count on all the term "aaa" and count only once if the number in first column is the same. For eg, if i use a "grep -c aaa input" command, the count will be "8". However, i would want the count to be "6" instead since 2 numbers in the 1st... (7 Replies)
Discussion started by: Raynon
7 Replies

10. Shell Programming and Scripting

Repetitive Tasks: using if..then inside a loop

I thought I was getting pretty good with Bash but this problem is stumping me. Any suggestions would be greatly appreciated. I've written a firewall script that uses a lot of functions. The variables are read into the script from another .conf file earlier on in the code. Most of these... (2 Replies)
Discussion started by: garak
2 Replies
Login or Register to Ask a Question