Finding compound words from a set of files from another set of files
Hi All,
I am completely stuck here.
I have a set of files (with names A.txt, B.txt until L.txt) which contain words like these:
All the files from A.txt to L.txt have the same format i.e. complete words in newlines.
I have another set of text files (files names as 1.dat, 2.dat till n.dat where n is an integer number) which are complete texts like:
As you can see in the complete texts:
1. All are in lowercase.
2. No punctuation, no full-stops. Only alphabetical texts.
Task:
1. Open 1.dat
2. Open A.txt, B.txt, C.txt until L.txt
3. Find all the words from A.txt and the "word's position in A.txt i.e. its line number" (both single words and compound words like random access memory) which are there in 1.dat
4. Then open B.txt and find words and line numbers in 1.dat and do the same until L.txt
5. Then open 1.num and write the "average of the line numbers of the matching words from all the TXT files".
6. Then open 2.dat and again A.txt till L.txt and then make 2.num and keep doing until all DAT files have been read and all corresponding NUM files are being created. So, in the end I'll have as many NUM files as DAT files containing only one number in each of them which have the average of the line numbers in them.
I have done something and it indeed works very well in matching both single and compound words but I am not able to loop it up for files and find the average of the line number. I have used PERL but for me sed or awk will also do as I just care for the output.
Well, I read your post one time, then tried one more, and at the third I saw that I couldn't understand.
Please give examples (for understanding and possible testing) of files B.txt, C.txt, 2.dat, 1.num, and 2.num.
I am very sorry for not being clear. I realized that I really don't make much sense in my first post.
I am trying to come up with a solution but got stuck in the file looping operation. This is what I intend to do.
Step by Step Procedure:
1. Open 1.dat
2. Open A.txt
3. Take the first word from A.txt (this word could be single or compound word like random access memory)
4. Search that first word in 1.dat
5. If the first word is found then store the value as 1 (in my case A.txt means 1, B.txt means 2, C.txt means 3 until L.txt which is 12)
6. If the second word is found from A.txt in 1.dat then add 1 to the previous value
7. If again another word from A.txt matches in 1.dat, add 1 again to the previous value and keep adding them as they are found in 1.dat
8. When A.txt is EOF, take B.txt now and search 1.dat again (from beginning) and as and when a word is found keep adding "2" to the previous addition counter.
9. When B.txt is EOF, take C.txt and search 1.dat again. If any word which is present in C.txt and also in 1.dat, now keep adding "3" to the previous counter value as and when the match occurs.
10. Keep doing it until L.txt and for L.txt keeping adding 12 as and when matching occurs.
12. Now, take the mean (average) that is entire number of match that has occurred from A.txt to L.txt
13. Store this mean in 1.num
14. Now, take 2.dat and repeat the procedure from A.txt until L.txt
One thing that is important: When A.txt is being read and match occurs I only keep adding 1 as and when match happens else 0. For B.txt its 2, for C.txt its 3 etc until L.txt
Example.
Consider A.txt
Consider B.txt
Consider 1.dat
I read A.txt and extract "computer" from it. A.txt is 1
I then search "computer" in the entire text 1.dat and luckily find it in 1.dat. I only have to find match once even if "computer" exists several times. Now, I store this value in some array or variable as 1
I then goto line 2 of A.txt and extract "random access memory". I again search 1.dat for the presence of "random access memory" and BINGO!! found it again and store in the array or variable as 1 as it is in line in A.txt
I do it for entire A.txt and now I find none. So, I goto B.txt
I have an addition counter. So, now my addition counter has 2 (1+1) until now.
Now, I read B.txt
"rom" found in text and hence now add "2" to the previsous addition counter.
"flash" found again add 2 again to the previous counter.
Now I open C.txt and keep adding 3 if found.
Suppose, none of the other TXT files contain any matching words. So, my final addition counter is 6 (1+1+2+2=6 from A.txt and B.txt matches) and mean is 6/4 = 1.5 and store this value in 1.num. (4 is the number of times matches occur)
When all done until L.txt, then I begin the same procedure with 2.dat (and store result in 2.num) until all DAT files have been read.
I think the complexity has increased due to many files else its very simple.
---------- Post updated 08-27-11 at 01:26 PM ---------- Previous update was 08-26-11 at 11:48 PM ----------
Hi All,
After bit of work, I came up with my own code. I am not a PhD in shell scripting but can do farely well in C (I know this section of the forum is not for C codes!). I am pasting my code below so that in future if any one who comes across a similar problem; one can use my code straight away or with a bit of modification according to the needs.
This is what one needs to do in order to run this code.
Place all the .txt and .dat files in one directory and run this code. One case see a file named average_values.res created when the code completes execution. I have used GNU GCC for compiling and creating the binary.
In case any one cannot understand the code, kindly comment here and I shall happily respond.
Hi All,
I have a list of words (these are actually a list of database table names separated by comma).
Now, I want to find only the non-existing list of words in the *.java files of current directory and/or its sub-directories.
Sample list of words:... (8 Replies)
Hi,
I am looking for a shell script which serves the below purpose.
Please find below the algorithm for the same and any help on this would be highly appreciated.
1)set of strings need to be replaced among set of files(directory may contain different types of files)
2)It should search for... (10 Replies)
All,
I am trying to find a set of files, it could be one file OR set of file ,
all with extension .DAT
I need to do some acticity, only if the files exist in a partificular folder
like
if ; then
CntV=`ls $Landing/*.DAT |wc -l`
echo "Lst Value " $Cnt... (3 Replies)
Greetings.
I am a UNIX newbies.
I am currently facing difficulties dealing with a large data set and I would like to ask for helps. I have a input file like this:
ak 1 AAM1
ak 2 AAM1
ak 3 AAM1
ak 11 AMM2
ak 12 AMM2
ak 13 AMM2
ak 14 AMM2
Is there any possibility for me to... (7 Replies)
Hi guys, I have a file with a list of phoneme for words, it looks like this:
AILS EY1 L Z
AIMLESSLY EY1 M L AH0 S L IY0
AIMONE EY1 M OW2 N
AIMS EY1 M Z
AINGE EY1 NG
AINGE(2) EY1 N JH
AINLEY EY1 N L IY0
AINSLIE EY1 N Z L IY0
AIR EH1 R
AIRBAGS EH1 R B AE2 G Z
and I need to... (5 Replies)
Hi,
I have a set of simple, one columned text files (in thousands).
file1:
a
b
c
d
file 2:
b
c
d
e
and so on. There is a collection of words in another file:
b d
b c d e
I have to find out the set of words (in each row) is present or absent in the given set of files. So, the... (4 Replies)
Hi Everyone!!!
Is there any command to move/copy set of files in a specific range.
Eg :
I have 800 text files in a directory
A1 ... A800
I would like to copy only files in range A40 ... A250.
I can acheive this using a "for" loop , but I guess there could be some command or... (8 Replies)
Hello
I have a ton of files in a directory of the format app.log.2008-04-04
I'd like to run a command that would archive each of these files as app.log.2008-04-04.tgz
I tried a few combinations of find with xargs etc but no luck.
Thanks
Amit (4 Replies)
Hi Frineds,
I want to delete a set of files which are older than 7 days from teh current date.I am totally enw to shell scripting, can anyone help me with a sample code to list out the files which are older and then remove them from the directory.
Please help
THanks
Viswa (5 Replies)