-----------------------------------------------------------------------
Dear Kenny
Excuse me that I forgot to give my OS on which I work.
I'm using Linux (bash) under CYGWIN.
I wanted to attach my script and the input files to my question but I didn't find a button for the attachment.
Nevertheless below is my script, which generates also the output filename.
=======================================
#! /usr/bin/awk -f
#======================================
# Author: Mohsen Owzar
# Date: 25.11.2014
# Filename: RecognizeSlotNr.awk
#======================================
# Description:
# e.g.
# RecognizeSlotNr.awk <Filename>
# RecognizeSlotNr.awk LOG_16.txt
#======================================
# BEGIN Part
#======================================
BEGIN {
FILE = ARGV[1]
FILE1 = FILE
FirstEncoderNr = 2000
sub(/\.txt/, "", FILE1)
OUT = FILE1 "_Nr.txt"
print "Processing ==> " FILE > OUT
print "******************************" > OUT
NAM_Before = ""
}
#======================================
# MAIN Part
#======================================
{
N++
NAM = $1
sub(/EA/, "", NAM)
NAM = NAM + 0
Diff = NAM - FirstEncoderNr
SlotNr = int(Diff / 6) + 1
CNT[SlotNr]++
if (NAM != NAM_Before) {
NAM_CNT ++
ENC_NAM[++M] = NAM
}
NAM_Before = NAM
# printf("%-8s%-8s%-8s\n", NAM, Diff, SlotNr)
}
##======================================
## END Part
##======================================
END {
print "The number of Encoders is: " NAM_CNT "\n" > OUT
printf("%-8s%-4s\n", "ENC", "Nr") > OUT
print("***********") > OUT
for (i = 1; i <= M; i++) {
Diff = ENC_NAM[i] - FirstEncoderNr
Nr = int(Diff / 6) + 1
printf "%-8s%-4s\n", ENC_NAM[i], Nr > OUT
}
print "****************" > OUT
for (i in CNT) {
printf "Slot %-4s ==> %-4s\n", i, CNT[i] > OUT
}
print "\nThe generated File is ==> " OUT
}
==============================================
As you wrote in your answer, I tried to write a shell script to manage this problem (GiveNutzenNr.sh). This script is as the following:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#! /usr/bin/bash
# Filename: GiveNutzenNr.sh
# It concatenates all single logfiles into one big logfile.
# It replaces the date and time into the name of the logfile.
IN_File=$*
RecognizeSlotNr.awk $IN_File
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
As I wanted to run this script as the following:
$ GiveNutzenNr.sh LOG_??.txt
./GiveNutzenNr.sh: Zeile 5: $'\r': Kommando nicht gefunden.
« kann nicht zum Lesen geöffnet werden (No such file or directory)
It brought the above Error message, even if all the Logfiles are there.
I have used this construction (shell script) before and it has worked well. I don't know what now the problem is.
I thought that inside the awk program is not a problem to gather all the files with wildcards e.g. "LOG_??.txt".
In this case you don't need a wrapper shell script to use the AWK script.
best regards
Mohsen