Shell script to read a text file line by line & process it...

Hi ,

I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144
Now my script will check :
1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty.
2)then it executes a shell script called "ANES.sh" (script1)
3)this loop countinues until all entries in text file are processed
4) give exit to loop
5) then executes another script (script2) with -r -y option

Also I want to capture error messages and create log file for this script.
-------------------------------------------------
MY CODE:

#! /bin/sh

GDCMD=path to script1
RAFOL=path to script2
TEXTFILE=path to text file



while read line    
do    
  
$GDCMD 

done <textfile.txt 

$RAFOL -r -y 2009

-------------------------------------------------------
I know that I have not put any loop here to execute script1 for each entries of text file. Also i have not out any exit coomand & not captured any log files.Kindly help.

Thanks to all!!!

does it work?

awk --re-interval '/[0-9]{5}/{system("path/to/script1.sh")} END{system("path/to/script2.sh")}' yourInput.txt

@sk1418 : script run with no errors but it didnt execute my shell scripts ....i mean it didnt print anyhitng that i put in scripts 1 & 2!

i don't know what is in your script. Your script should be executed.

if you try:

awk --re-interval '/[0-9]{5}/{system("echo \"hit\"")} END{system("seq 10")}' yourInput.txt

you will see one "hit" for each "5 numbers line". and at the end print a sequence 1-10.

---------- Post updated at 13:15 ---------- Previous update was at 13:11 ----------

update
you could try this:

system("sh path/to/your/script.sh")

Hi,

Can you please help me to check the format of a number in a file

ex: that each entry is only 5 digits & numeric only, no alphabets, & its not empty.ex: 34150

it should also give message if the format is wrong

I used :

if ! echo "$line" | grep '[0-9]\{5\}$' >/dev/null 2>&1 ; then
error_msg "AVL format is invalid" >> ${LOG_FILE}
exit 1
fi

 
grep -wv "[0-9]\{5\}" filename

This doesnt show anything on the screen???

Also i need message for fail execution

Thanks...

echo "yourStringToBeTested" |grep -E "[0-9]{5}" && echo "ok" || echo "wrong"

system() call inside awk will not print anything on the screen I guess! But your script should get executed. You can redirect the output to some log and check.

/user/ahamed $ echo 1 | awk '{system("echo printme")}'
/user/ahamed $

--ahamed