begin end detection

Hi all,
i am new to scripting. i need to write a code to detect begin and end of word that either begins or ends with t,th,d,dh,s,sh

i have a set of words in a file containg one word per line. let the filename be aaa.txt.
i have an another file bbb.txt which has two lines, just specifying the time
0.897
1.567

if the word begins with the above specified letters, then i need to subtract 0.100(500msec) to first line
if the word ends with the above specified letters, then i need to add 0.200(200msec) to second line
saving them into another file

please help me

what have you got

hey sorry in the previous post i specified only one second file.
I have 100 words in aaa.txt
similarly i have 100 other files corresponding to those words.

for every word, i have to load the corresponding file that contains the time(two lines). If the word in aaa.txt begins with t,th,d,dh,s,sh then i need to subtract 100msec from the first line of the corresponding word file and if it ends with t,th,d,dh,s,sh then i need to add 200msec to the secong line of that corresponding word file

let the word corresponding "time files" are 1.txt, 2.txt,....100.txt
its better if a create a new "time files"

-----Post Update-----

hey sorry in the previous post i specified only one second file.
I have 100 words in aaa.txt
similarly i have 100 other files corresponding to those words.

for every word, i have to load the corresponding file that contains the time(two lines). If the word in aaa.txt begins with t,th,d,dh,s,sh then i need to subtract 100msec from the first line of the corresponding word file and if it ends with t,th,d,dh,s,sh then i need to add 200msec to the second line of that corresponding word file

let the word corresponding "time files" are 1.txt, 2.txt,....100.txt
its better if a create a new "time files"

looks like a homework question....

this is against the forum rules :cool:

Try this:

awk 'FNR==NR{a[NR]=$0;p=a[1];q=a[2];next}/^[t|th|d|dh|s|sh]/{p=p-0.100}
/[t|th|d|dh|s|sh]$/{q=q-0.200}
END{print p,q}' aaa.txt word

-Devaraj Takhellambam

Hi,
This is not my home work problem. I am doing research work and i need this code to generate that time, manually its taking more time. So i choosed this scripting

In the above post what is this "aaa.txt word". Can we assign two files to awk command?

-----Post Update-----

i am getting an error
awk: line 1: Syntax error at or near =

-----Post Update-----

i am getting an error
awk: line 1: syntax error at or near =

-----Post Update-----

i am getting an error
awk: line 1: syntax error at or near =

-----Post Update-----

Hi,
i solved the error, its my mistake
the awk command is taking only first word each time from aaa.txt

here's my code

if [ $# -ne 2 ]
then
echo "Usage:./time_to_ehmm <input dir> <word file>"
exit 1
fi

for i in $1/*.lab
do
awk 'FNR==NR {a[NR]=$0;p=a[0];q=a[1];next}/^[t|th|d|dh|s|sh]/{p=p-0.100}/[t|th|d|dh|s|sh]$/{q=q+0.200}; END {print p,q}' $2 $i

#read -p "press enter"
done

-----Post Update-----

any suggestions please

Thanks

-----Post Update-----

any suggestions please

Thanks

It should be in this sequence as per your first post. They are filename.
bbb.txt aaa.txt

Use a for loop and iterate through it.

Thank you.. i solved the problem