Separate text files in a folder by word count


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Separate text files in a folder by word count
# 1  
Old 03-15-2011
Separate text files in a folder by word count

Hi, been searching Google for like an hour and I doubt I got the right keywords so might as well ask here.

What I need:
Before:
Article1.txt 564
Article2.txt 799
Article3.txt 349
Article4.txt 452

* Separate files over 400 wordcount *

After:
Article1.txt 564
Article2.txt 799
Article4.txt 452

New Folder
Article3.txt 349
# 2  
Old 03-15-2011
Hi,

A little bashscript can help here:
Code:
#!/bin/bash
wc -w Article*.txt |while read WORDS FILE
do
   [ $WORDS -le 400 ] && mv $FILE /path/to/new/folder
done

# 3  
Old 03-15-2011
A little enchancement of cero's bashscript
Code:
#!/bin/bash
wc -w Article*.txt | head -n-1 | while read WORDS FILE
do
   [ $WORDS -le 400 ] && mv $FILE /path/to/new/folder
done

The script will not try to move the "total" file and get the following error:
Code:
mv: cannot stat `total': No such file or directory

# 4  
Old 03-15-2011
Hi,
follow this code:
ls -l Article*.txt > file
for i `cat file`
do
file=i
count=`cat file|wc -w`
if [ $count -ge 400 ]; then
move $file1 dir/$file
fi
done
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Separate columns into different text files

Hi I have large text file consisting of five columns. Sample of the file is give below: ed 2-4 12.0 commons that they depended on. मानवों नष्ट किया जिन पर वो आधारित थे। ed 3-1 12.0 Almost E, but would be over. रचना करीब करीब ई तक जाती है, मगर तब तो नाटक ख़त्म हो... (2 Replies)
Discussion started by: my_Perl
2 Replies

2. Shell Programming and Scripting

Word count files in UNIX

My files: file1 and file2 contain 157 words. Emptyfile1 contain 0 words. My script has to output how many files is filled with words and how many that are not. If there are files that have words in it. It has to output "file2 and file2 contains 157 words, 0 files are empty" If not every... (9 Replies)
Discussion started by: johnrichards
9 Replies

3. Shell Programming and Scripting

Word count in html files

Hi does somebody know how to do a word count in a .html file? Just the text words, without all the html code. Thanks (4 Replies)
Discussion started by: louisJ
4 Replies

4. Shell Programming and Scripting

total count of a word in the files

Hi Friends, Need help regarding counting the word "friend" in files test1.txt and test2.txt. ( there is no gap/space between word ) cat test1.txt himynameisrajandiamfriendofrajeshfriend wouldyouliketobemyfriend. cat test2.txt himynameisdostandiamfriendofdostfriend... (2 Replies)
Discussion started by: forroughuse
2 Replies

5. Shell Programming and Scripting

Splitting text file into 2 separate files ??

Hi All, I am new to this forumn as well to the UNIX, I have basic knowledge of UNIX which I studied some years ago, now I have to do some shell scripting to load data into Oracle database using sqlldr utility, whcih I am able to do. I have a requirement where I need to do following operation. I... (10 Replies)
Discussion started by: shekharjchandra
10 Replies

6. UNIX for Dummies Questions & Answers

How to obtain a count of files in a folder and it's subfolders

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)
Discussion started by: scarfinv
2 Replies

7. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

8. UNIX for Dummies Questions & Answers

Word Count for a range of text

Help Please! I have alot of text that I would like to count for a range of text. logevents.1:<190> Oct 30 02:59:42 N/A : 6|4145|RC|CAC: Terminated logevents.1:<190> Oct 30 02:59:42 N/A : 6|4097|RC|CAC: Deleted logevents.1:<190> Oct 30 02:59:44 N/A : 6|4145|RC|CAC: Terminated ... (5 Replies)
Discussion started by: bpfoster7
5 Replies

9. UNIX for Dummies Questions & Answers

word count ascii files

how do I display the total number of words in a file which is of the type ascii text (1 Reply)
Discussion started by: madtim
1 Replies
Login or Register to Ask a Question