#!/bin/bash
# name of script zetzwo.sh #
# from IBM-tutorial, set a silent exit, if a condition is not true #
# unless it is part of a sequence of commands #
# http://www.ibm.com/developerworks/aix/library/au-usingtraps/ #
set -e
set -u
machine="Today at: ";
machine=$(printf "%s %s" "$machine" "$(uname -n)");
R=`date +%A' der '%d'/'%m'/'%y' the '%V'.'Week`;
V=`date +%x`; #will be used later on, Locale (e.g. 31.12.1999)
T=$((86400/3600)); #24 hours, the hard way
echo $T "not yet";
# shows the actual user
echo $USER;
if (( "$T" < 24 ))
then
echo "today is" $R
else :
fi;
stringZ=`uptime`
stringZ=$(printf "%s %s" "$stringZ" $V)
# Variable bucket and bucket2 for the two little databases to work with #
bucket=(/home/$USER/logger/uplog.txt)
bucket2=(/home/$USER/logger/uplog-two.txt)
echo "uptime" $USER " " $machine " " ${stringZ:13:5} && echo ${stringZ} >> $bucket |
awk ' {NR~/^1$/ NR~/^30$/} END { OFMT="%4f"; ORS ":"; print ENVIRON["USER"]"\t" $3,$11 } ;'
$bucket >> $bucket2;
awk ' {max = 0} {if ($2>max) max=$2} END {OFMT="%6f"; ORS ":"; print max};' $bucket2;
awk ' {sum=sum+$2} END {OFMT="%2f"; ORS ":"; print sum/NR};' $bucket2; #average
While this conception works properly, creating a second database named bucket2 I can go on for the calculation in awk and delete the whole file after 30 days with some bash like this
Code:
find /path/to/files* -type f -mtime +30 -exec rm '{}' '+'
and setting "wait" to create a new one, just because I only wanted to make that calculation for that period.
@Don Cragun, all I could find about awk-printing format to fit in this was the up above.
Sure there is one weakness in that. If I switch on an off my computer several times per day, that would mean to create for each day one seperate file.
This is the output of bucket2, the one to be calculated.
I have a file which is one big long line of text about 10Kb long.
Can someone provide a way using awk to introduce carriage returns every 40 chars in this file.
Any other solutions would also be welcome.
Thank you in advance. (5 Replies)
Hi there, I have a text file with several colums separated by "|;#" I need to search the file extracting all columns starting with the value of "1" or "2" saving in a separate file just the first 7 columns of each row maching the criteria, with replacement of the saparators in the nearly created... (4 Replies)
I have a file with 8 fields. I need the subtotals for fields 7 & 8 when field 5 changes.
cat wk1
01/02/2011/18AB/17/18/000000071/000000033
01/02/2011/18AB/17/18/000000164/000000021
01/02/2011/18AB/17/18/000000109/000000023
01/02/2011/28FB/04/04/000000000/000000000... (2 Replies)
Hi,
Here i have to check first record $3 $4 with second record $1 $2 respectively. If match found, then check first record $2 == second record $4 , if it equals , then reduce two records to single record like as desired output.
Input_file
1 1 2 1
2 1 3 1
3 1 4 1
3 1 3 2
desired... (3 Replies)
Hi,
how do i read a file using awk for a given no of line?
e.g
1. read only first 50 line.
2. read starting from line 20 to line 60..
thanks in advance.
-alva (8 Replies)
I want to count lines of a file using AWK (only) and not in the END part like this awk 'END{print FNR}' because I want to use it.
Does anyone know of a way?
Thanks a lot. (7 Replies)
Sorry for the weird title but i have the following problem.
We have several files which have between 10000 and about 500000 lines in them. From these files we want to remove lines which contain a pattern which is located in another file (around 20000 lines, all EAN codes). We also want to get... (28 Replies)
The output of an awk script is the below file. Line 1,3 that starts with the Ion... need to be under line 2,4 that starts with R_. The awk runs but no output results. Thank you :).
file
IonXpress_007 MEV37
R_2016_09_20_12_47_36_user_S5-00580-7-Medexome
IonXpress_007 MEV40... (6 Replies)
The awk below executes and is close (producing the first 4 columns in desired). However, when I add the sum of $7, I get nothing returned. Basically, I am trying to combine all the matching $4 in f1 and output them with the average of $7 in each match. Thank you :).
f1
... (2 Replies)
Discussion started by: cmccabe
2 Replies
LEARN ABOUT LINUX
igawk
IGAWK(1) Utility Commands IGAWK(1)NAME
igawk - gawk with include files
SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ...
igawk [ all gawk options ] [ -- ] program-text file ...
DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1).
AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like
@include getopt.awk
in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path.
OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports.
EXAMPLES
cat << EOF > test.awk
@include getopt.awk
BEGIN {
while (getopt(ARGC, ARGV, "am:q") != -1)
...
}
EOF
igawk -f test.awk
SEE ALSO gawk(1)
Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995.
AUTHOR
Arnold Robbins (arnold@skeeve.com).
Free Software Foundation Nov 3 1999 IGAWK(1)