05-30-2002
You can use the $r from the first loop by adding a second for statement in the middle of the second one. Then you can replace the "0-6" with "$r" instead!
It looks like you are reading $i twice. Once in the for statement and then again with the "cat $i". I am not sure if you are using data in the $i or just using it for the looping or both. So you may need to keep that portion.
1) move the first done to the end of the whole script
2) use the $r from the first loop for the second loop. I try to use variables wherever possible.
cd /opt/daybreakp/logs
for i in accx24oac.log crbx01.log.X1 cssx108oac.log dbkx05.log dbkx12.log dbkx13.log glix10oac.log salx17oac.log
do
for r in "0 1 2 3 4 5 6"
cat $i | awk '($1 == "'${DAY[$r]}''" ) {print $0}' > /tmp/$i.tmp
mv /tmp/$i.tmp $i
done
done
I am not sure that is what you want above. MAYBE LIKE THIS NEXT ONE BELOW...
cd /opt/daybreakp/logs
for i in accx24oac.log crbx01.log.X1 cssx108oac.log dbkx05.log dbkx12.log dbkx13.log glix10oac.log salx17oac.log
do
for r in "0 1 2 3 4 5 6"
cat $i | awk '($1 == "'${DAY[$r]}'" ||
$1 == "'${DAY[$r]}'" ||
$1 == "'${DAY[$r]}'" ||
$1 == "'${DAY[$r]}'" ||
$1 == "'${DAY[$r]}'" ||
$1 == "'${DAY[$r]}'" ||
$1 == "'${DAY[$r]}'" ) {print $0}' > /tmp/$i.tmp
mv /tmp/$i.tmp $i
done
done
The less hardcoding of values and the more variables that you use the less headache you will have later or when someone else has to edit your code.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am having a problem with awk when I run it with a loop. It works perfectly when I echo a single line from the commandline. For example:
echo 'MFG009 9153852832' | awk '$2 ~ /^0-9]$/{print $2}'
The Awk command above will print field 2 if field 2 matches 10 digits, but when I run the loop... (5 Replies)
Discussion started by: cstovall
5 Replies
2. Shell Programming and Scripting
I am pretty new to this, but imagine what I am trying to do is possible
iI am trying to make an automated DB comparison tool that selects all columns in all tables and compares them to the same thing in another DB.
anyway I have created 2 files to help with this
the first file is a... (13 Replies)
Discussion started by: Zelp
13 Replies
3. Shell Programming and Scripting
Hi
I have a file which is having following text. The file is in a tabular form with 5 fields. i.e field1, field2 ..... field5 are its columns and there are many rows in it say COUNT is the number of rows
Field 1 Field2 Field3 Field4 Field5
------- ------- ... (8 Replies)
Discussion started by: skyineyes
8 Replies
4. UNIX for Dummies Questions & Answers
I'm trying to parse a configuration text file using awk. The following is a sample from the file I'm searching. I can retrieve the formula and recipe names easily but now I want to take it one step farther. In addition to the formula name, I would like to also get the value of the attribute... (6 Replies)
Discussion started by: new2awk
6 Replies
5. Shell Programming and Scripting
How do I remove last comma?
echo "xx yy zz" | awk 'BEGIN{FS=" "}{for (i=1; i<=NF; i++) printf "%s,", $i}'output:
xx,yy,zz,
required output:
xx,yy,zz
or (ideally!):
xx, yy & zz
many thanks in advance! (4 Replies)
Discussion started by: euval
4 Replies
6. Shell Programming and Scripting
Hi all, I have a file containing 5000 rows and 4 columns. I need to do a loop within the rows based on the values of column 3. my sample data is formatted like the ones below: what i need to do is to make a loop that will allow me to plot the values of x,y,values corresponding to month 1 to month... (10 Replies)
Discussion started by: ida1215
10 Replies
7. Shell Programming and Scripting
I would like to loop over variables i and j consecutively,
{ a = -6.7
b = 7.0
c =0.1
{ for (i = 0; i<=(b-a)/c; i++)
for (j = 1; j<=(b-a)/c; j++)
'$1<=(a+j*c)&&$1>=(a+i*c)' FILENAME > output_j
'{print $2}' output_j > output_j_f
}
I essentially want to print the range of $1... (9 Replies)
Discussion started by: chrisjorg
9 Replies
8. Shell Programming and Scripting
Hi all,
please help me construct the command. i want to loop through all files named bam* and bed*. My awk works for a particular pair but there are too many pairs to do manually.
I have generated multiple files in a folder in a given pattern. The files are named like
bam_fixed1.bam... (2 Replies)
Discussion started by: newbie83
2 Replies
9. Shell Programming and Scripting
I have the data like this:
PONUMBER,SUPPLIER,LINEITEM,SPLITLINE,LINEAMOUNT,CURRENCY
IR5555,Supplier1,1,1,83.1,USD
IR5555,Supplier1,1,3,40.4,USD
IR5555,Supplier1,1,6,54.1,USD
IR5555,Supplier1,1,8,75.1,USD
IR5556,Supplier2,1,1,41.1,USD
IR5556,Supplier2,1,3,43.1,USD
... (3 Replies)
Discussion started by: jeffreybsu
3 Replies
10. Shell Programming and Scripting
I am trying to parse a text file and send its output to another file but I am having trouble conceptualizing how I am supposed to do this in awk.
The text file has a organization like so:
Name
Date
Status
Location (city, state, zip fields)
Where each of these is on a separate line in... (1 Reply)
Discussion started by: kellyanneghj
1 Replies
LEARN ABOUT DEBIAN
unbuffer
UNBUFFER(1) General Commands Manual UNBUFFER(1)
NAME
unbuffer - unbuffer output
SYNOPSIS
unbuffer program [ args ]
INTRODUCTION
unbuffer disables the output buffering that occurs when program output is redirected from non-interactive programs. For example, suppose
you are watching the output from a fifo by running it through od and then more.
od -c /tmp/fifo | more
You will not see anything until a full page of output has been produced.
You can disable this automatic buffering as follows:
unbuffer od -c /tmp/fifo | more
Normally, unbuffer does not read from stdin. This simplifies use of unbuffer in some situations. To use unbuffer in a pipeline, use the
-p flag. Example:
process1 | unbuffer -p process2 | process3
CAVEATS
unbuffer -p may appear to work incorrectly if a process feeding input to unbuffer exits. Consider:
process1 | unbuffer -p process2 | process3
If process1 exits, process2 may not yet have finished. It is impossible for unbuffer to know long to wait for process2 and process2 may
not ever finish, for example, if it is a filter. For expediency, unbuffer simply exits when it encounters an EOF from either its input or
process2.
In order to have a version of unbuffer that worked in all situations, an oracle would be necessary. If you want an application-specific
solution, workarounds or hand-coded Expect may be more suitable. For example, the following example shows how to allow grep to finish pro-
cessing when the cat before it finishes first. Using cat to feed grep would never require unbuffer in real life. It is merely a place-
holder for some imaginary process that may or may not finish. Similarly, the final cat at the end of the pipeline is also a placeholder
for another process.
$ cat /tmp/abcdef.log | grep abc | cat
abcdef
xxxabc defxxx
$ cat /tmp/abcdef.log | unbuffer grep abc | cat
$ (cat /tmp/abcdef.log ; sleep 1) | unbuffer grep abc | cat
abcdef
xxxabc defxxx
$
BUGS
The man page is longer than the program.
SEE ALSO
"Exploring Expect: A Tcl-Based Toolkit for Automating Interactive Programs" by Don Libes, O'Reilly and Associates, January 1995.
AUTHOR
Don Libes, National Institute of Standards and Technology
1 June 1994 UNBUFFER(1)