Script does not run properly

Hello everybody

Im learning bash scrpting language and im making a script that read a file line by line and it does a comparison if in a line start with a letter or number and it will delete every ones that start with a letter. But im getting some errors

First of all, this is the script's code

The error that im getting is when the process arrive to while. It starts the conditional and never end. It always is running and showing numbers in the command line. I'd like to know how to solve this problem.

PD When i check out the arch.txt i see that the IF works fine, it delete every line that start with a letter. As i explained above, the problem is with while...

Thanks in advantage for any help that you could give me.

Grettings

try this

awk '/^[0-9]/' file


grep "^[0-9]" file

It doesnt work yet. The trouble is with the loop in the while, the way that i cut out the strings in the ' if ' works fine.

The infinite output is

and so on...

Thanks in advantage

Please post the input you have and the output you want. Without that, we can't even see how it's going wrong, let alone what or why.

I'm pretty sure you can do what you want with an awk one-liner instead of running sed 9,000 times to process 9,000 lines.

@alienrunes: first you are saving some column from each line in "myarchive.log" into $ARCHIVO (arch.txt), then in the while loop you are doing "sed" for the whole $ARCHIVO for each line in $ARCHIVO...

Hi, sorry for give a answer some late.

I could solve the problem from a different way. I've changed the "while" sentence for the "tr" and "grep" commands.

Well the main idea is to get the TIME spent by an user on internet. So, i pass as parameter the IP address and i get time expressed in seconds, but i need to clean that file from non-numerical character, so i delete any special or alphabetic character from that file. After, i delete the empty lines and add (+) the time 'till to get all seconds. After i convert it in hours:minutes:second. All expressed is the goal of this script. I leave below something i've done.

 
#SCRIPT GLOBAL VARIABLES
IP=$1
ARCHIVO=file1.txt
ARCHIVO2=file2.txt
ARCHIVO3=file3.txt
ARCHIVO4=file4.txt
TIEMPOTOTAL=file5.txt
SEGUNDOS=$(cat $ARCHIVO4)
TIEMPOF=file6.txt



echo "=============================================================="
echo "ANALIZANDO SOLICITUD DE TRAFICO POR NAVEGACION DE LA IP $IP"
echo "=============================================================="
cat firewallfile.log | grep src="$IP" | grep type=traffic | grep dst_port=80 | grep wan2 | cut -d ',' -f 22 | cut -d '=' -f 2 > $ARCHIVO

echo "=============================================================="
echo "OBTENIENDO INFORMACION DE NAVEGACION DE LA IP $IP"
echo "=============================================================="

cat $ARCHIVO | tr -d '[a-z][A-Z] =;:`"<>,./?!@#$%^&(){}[]' > $ARCHIVO2

echo "=============================================================="
echo "FORMATEANDO INFORMACION SOLICITADA"
echo "=============================================================="

grep . $ARCHIVO2 > $ARCHIVO3


awk '{ s += $1 } END { print s }' $ARCHIVO3 > $ARCHIVO4

echo "=============================================================="
echo "EL TIEMPO TOTAL NAVEGADO ES `cat $ARCHIVO4` SEGUNDOS"
echo "=============================================================="

echo "=============================================================="
echo "CONVIRTIENDO `cat $ARCHIVO4`  EN HORAS:MINUTOS:SEGUNDOS"
echo "=============================================================="


date -d '1970-01-01 '$SEGUNDOS' sec' +"%H:%M:%S" > $TIEMPOTOTAL


#echo - | awk -v "S=$SEGUNDOS" '{printf "%02d:%02d:%02d",S/(60*60),S%(60*60)/60,S%60}' > $TIEMPOTOTAL


echo "=============================================================="
echo "EL TIEMPO TOTAL NAVEGADO ES `cat $TIEMPOTOTAL` "
echo "=============================================================="

in addition with AWK (Commented in the script)

It works well, but when start to convert from seconds to hh:mm:ss , it shows me the following error.

awk: 1: unexpected character '.'

I've run the command in the console and it works very good. It gives me the time as i want, for instance

echo - | awk -v S=SECONDS S '{printf "%02d:%02d:%02d",S/(60*60),S%(60*60)/60,S%60}' > $TIEMPOTOTAL

Now, in addition with DATE Command

It show me weird values, if i run it with 3600 seconds, it convert in 01:00:00 as expected. But when it has big values, then show wrong value in the converter, for instance:

What can i do in these cases? Because i need to get real values from the converter between seconds to hours:minutes:seconds . If there is a way more easy to do it, just let me know how make it.

Thanks in advantage.

Greetings