unique words in files of folder and its subfolders
Hello, I tried to count all unique words of all files in one folder and its subfolders. Can anybody say me, why this doesnt work:
???
Cat writes only the names of those files, but not the wors, which should be in them.
Thanks for any advice.
Faculty of Mathematics and Physics, Charles University in Prague, The Czech Republic, Ondrej Tichy, ms.mff.cuni.cz/~ticho6am
Firstly you need to traverse the tree looking for files (not directories) with "find" and then get "cat" to display the contents. This example uses "cat -v" to guard against processing a file containing control characters.
Though we know nothing about your data this example uses "tr -s" to remove duplicate space and tab characters before translating space or tab into newline (similar to your code).
The most important bit is the "sort" which is imperative before running "uniq".
The "sort" command is the only command name which was not mentioned in your original post. I've tried to avoid introducing anything more exotic in case you have not yet covered a command on your course.
This may not fully match your requirement but should get you moving:
Might well need refining to deal with blank lines etc. .
When testing, try building the pipeline command-by-command and looking at the output after each new addition to the pipeline.
Whether you use "uniq" or "uniq -u" or whatever is up to your understanding of the phrase "all unique words".
Last edited by methyl; 03-10-2011 at 10:12 AM..
Reason: Forgot the "wc -l"
I have a folder with 4000 (*3) files like
gr_q4_gb-1.anc
gr_q4_gb-1.anc_cdr_st.txt
gr_q4_gb-1.anc_cdr_tr.txt
gr_q4_gb-2.anc
gr_q4_gb-2.anc_cdr_st.txt
gr_q4_gb-2.anc_cdr_tr.txt
gr_q4_gb-3.anc
gr_q4_gb-3.anc_cdr_st.txt
gr_q4_gb-3.anc_cdr_tr.txt
.
.
gr_q4_gb-4000.anc... (6 Replies)
Hello,
Neither ‘Grep -r' nor ‘grep -R' is working in my environment. (Searching for a text pattern in the files)
Any suggestions... Using SunOS 5.9
Thanks,
Trinanjan. (1 Reply)
How can this be done?
I mean, I want to search for all *png *jpg *bmp files in my ~/Pictures/ folder....How can I list them?
Thank you geeks :) :b: (2 Replies)
First of all, the extent of my unix knowledge is next to nil. I've been able to telnet to a unix box, and thanks to the Computer Hope website, I've been able to learn a few basic commands to navigate from folder to folder, and view contents.
What I really need to do is obtain a count of all... (2 Replies)
Hello,
I have two folders.
One has 1183 text files (folder A).
The other (folder B) has 1160 of those 1183 files (the contents in these 1160 files are identical to the contents in the corresponding files in the other folder, but the names of the files in this folder are completely different... (2 Replies)
Hi,
I am trying to write a shell script to delete logs generate by db when space in the folder reaches 70%. i am getting space values from db, find the files at OS and remove them by using a cron job runs every 5minutes.
I have to keep the latest 5 files at any time, my problem is that log files... (3 Replies)
i need to change string in all files in current folder and all subfolders. i wrote the following script. It works good except it dont delete temp file from subfolders.
for z in `find . -type f -name "*.html" -o -name "*.htm"`; do
sed -e 's@abc@xyz@g' $z>temp;
mv temp $z;
done
any idea?... (1 Reply)
A painfully rudimentary UNIX question for somebody. I've been puzzling over this for the last hour but can't find the right command.
I'm simply trying to get a list of all files - and their full paths - within a folder & subfolders which have extension .php and .js. That's it! No amount of... (1 Reply)