Text analysis


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Text analysis
# 8  
Old 03-30-2011
Quote:
Originally Posted by John0101
Hey Guys

I recently posted yesterday about trying to count the amount of separate words that exists in a text file e.g. walle.txt.
i want the output to give to give me a list of words with a number next indicating how many times its came up in the file e.g:
cat 20
the 11
if 40

I'm completely new to Unix, I'm currently using the bash terminal from a Macbook Pro. I am running this on some example file scripts, is what i'm trying to do possible? if so please help.

Thanks
How the posted solutions NOT fulfilling the above request?
As always, please provide a sample input file a desired output (using code tags).
# 9  
Old 03-30-2011
Code:
xargs -n1 <yourfile.txt | sort | uniq -c

---------- Post updated at 05:59 PM ---------- Previous update was at 05:54 PM ----------

the simple quote may annoy xargs so we can change it into a white space at first with a sed statement :

Code:
sed "s/'/ /g" yourfile.txt | xargs -n1 | sort | uniq -c

# 10  
Old 03-30-2011
Hey,

Thanks for the reply, i just tried both statements and 'illegal argument count' keeps coming up :\
# 11  
Old 03-30-2011
Please upload your text file so we can try with a real example and we will let you know if some other step are needed

Try to go through a tempfile then.

give a try to this:

Code:
sed "s/'/ /g" yourfile.txt >file.tmp
xargs -n1 <file.tmp >file.tmp.2
sort file.tmp.2 >file.tmp.sorted
uniq -c file.tmp.sorted >wordcount.txt
rm file.tmp*
cat wordcount.txt


Last edited by ctsgnb; 03-30-2011 at 01:22 PM..
# 12  
Old 03-30-2011
Okay Thanks,

I've attached it below
# 13  
Old 03-30-2011
OMG ... i doesn't really look like a txt file, but more like a binary file !
(... forget my previous post)
give a try to this:

Code:
strings yourfile.txt | sed "s/'/ /g" | xargs -n1 | sort | uniq -c

# 14  
Old 03-30-2011
I gave it a go and it still says 'illegal argument count' :/
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Infrastructure Monitoring

Nmon Analysis

Dear All, I am an performance tester. Now i am working in project where we are using linux 2.6.32. Now I got an oppurtunity to learn the monitoring the server. As part of this task i need to do analysis of the Nmon report. I was completely blank in this. So please suggest me how to start... (0 Replies)
Discussion started by: iamsengu
0 Replies

2. UNIX for Dummies Questions & Answers

Help with text analysis - UNIX

Hey Guys I recently posted yesterday about trying to count the amount of separate words that exists in a text file e.g. walle.txt. i want the output to give to give me a list of words with a number next indicating how many times its came up in the file e.g: cat 20 the 11 if 40 I'm... (0 Replies)
Discussion started by: John0101
0 Replies

3. Shell Programming and Scripting

Analysis of a script

what does this line in a script mean?? I have tried to give it at the command prompt and here is what it returns ksh: /db2home/db2dap1/sqllib/db2profile: not found. . /db2home/db2dap1/sqllib/db2profile i have tried the same thing for my home directory too and the result is the same .... (5 Replies)
Discussion started by: ramky79
5 Replies

4. Shell Programming and Scripting

Metacharacters analysis

:confused:Hi , Can someone please advise what is the meaning of metacharacters in below code? a_PROCESS=${0##*/} a_DPFX=${a_PROCESS%.*} a_LPFX="a_DPFX : $$ : " a_UPFX="Usage: $a_PROCESS" Regards, gehlnar (3 Replies)
Discussion started by: gehlnar
3 Replies

5. Shell Programming and Scripting

text file analysis

Hello, I have a text file containin 4 lines which are repeated along the file, ie the file looks like this: 16:20:12.060769 blablabla 40 16:20:12.093199 blablabla 640 16:20:12.209003 blablabla 640 16:20:12.273179 blablabla 216 16:20:27.217444 blablabla 40 16:20:27.235410 blablabla 640... (2 Replies)
Discussion started by: Celine19
2 Replies

6. Programming

Regarding stack analysis

I would like to know how I could do the following : void func(){ int a = 100; b=0; int c = a/b; } void sig_handler (int sig,siginfo_t *info,void *context){ //signal handling function //here I want to access the variables of func() } int main(){ struct sigaction *act =... (7 Replies)
Discussion started by: vpraveen84
7 Replies

7. Shell Programming and Scripting

AWK script: decrypt text uses frequency analysis

Ez all! I have a question how to decrypt text uses letter frequency analysis. I have code which count the letters, but what i need to do after that. Can anybody help me to write a code. VERY NEEDED! My code now: #!/usr/bin/awk -f BEGIN { FS="" } { for (i=1; i <= NF; i++) { if ($i... (4 Replies)
Discussion started by: SerJel
4 Replies

8. Solaris

Catalina Analysis

How can I make analysis for catalina.out (2 Replies)
Discussion started by: Burhan
2 Replies
Login or Register to Ask a Question