Gentoo Archives: gentoo-user

From: Ow Mun Heng <Ow.Mun.Heng@×××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Help with bash/awk script
Date: Wed, 23 Aug 2006 14:42:34
Message-Id: 1156343437.6040.4.camel@neuromancer.home.net
1 I'm trying to figure out how to do this sequence in this bash script.
2 The problem I'm having is how to make $i to change according to the
3 changes in $x
4
5 My current solution is a bit of a hack and stupid.
6
7 One more thing, my current solution will parse the file _each_ time for
8 _each_value/head which essentially means it reads the file multiple
9 times. Is there a better way so to reduce the # of reads/parses? (Does
10 awk parse the file once or multiple times, that is if I were to rewrite
11 the below entirely in awk language)
12
13 Thanks
14
15
16 #!/bin/bash
17
18 filename=$1
19 heads=6
20 tpi=7
21 x=0
22 y=1
23 z=1
24 clear
25 while (( $x < $heads ))
26 do
27 finaltpi=`cat $1 | awk "/TPI chosen/" | awk -v pat="$x" '{if
28 (NR==pat+1) print $5}'`
29 while (( $y <= $tpi ))
30 do
31 if [ "$x" -eq 0 ]
32 then
33 for i in `seq 1 7` <-----
34 do
35 tpiert=`egrep -i "(average)" $1 | awk -v pat="$i"
36 '{ if(NR==pat) print $5","$10}'`
37 echo $filename,$x,$y,$finaltpi,$tpiert
38 ((y++))
39 done
40
41 elif [ "$x" -eq 1 ]
42 then
43 for i in `seq 8 14` <-----
44 do
45 tpiert=`egrep -i "(average)" $1| awk -v pat="$i"
46 '{ if(NR==pat) print $5","$10}'`
47 echo $filename,$x,$y,$finaltpi,$tpiert
48 ((y++))
49 done
50 elif [ "$x" -eq 2 ]
51 then
52 for i in `seq 15 21` <-----
53 do
54 tpiert=`egrep -i "(average)" $1 | awk -v pat="$i"
55 '{ if(NR==pat) print $5","$10}'`
56 echo $filename,$x,$y,$finaltpi,$tpiert
57 ((y++))
58 done
59 elif [ "$x" -eq 3 ]
60 then
61 for i in `seq 22 28` <-----
62 do
63 tpiert=`egrep -i "(average)" $1 | awk -v pat="$i"
64 '{ if(NR==pat) print $5","$10}'`
65 echo $filename,$x,$y,$finaltpi,$tpiert
66 ((y++))
67 done
68 elif [ "$x" -eq 4 ]
69 then
70 for i in `seq 29 35` <-----
71 do
72 tpiert=`egrep -i "(average)" $1 | awk -v pat="$i"
73 '{ if(NR==pat) print $5","$10}'`
74 echo $filename,$x,$y,$finaltpi,$tpiert
75 ((y++))
76 done
77 elif [ "$x" -eq 5 ]
78 then
79 for i in `seq 36 42` <-----
80 do
81 tpiert=`egrep -i "(average)" $1 | awk -v pat="$i"
82 '{ if(NR==pat) print $5","$10}'`
83 echo $filename,$x,$y,$finaltpi,$tpiert
84 ((y++))
85 done
86 fi
87 done
88 let "y=1"
89 ((x++))
90 done
91
92
93 --
94 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Help with bash/awk script Etaoin Shrdlu <shrdlu@×××××××××××××.org>
Re: [gentoo-user] Help with bash/awk script "Bo Ørsted Andresen" <bo.andresen@××××.dk>