Math with wordcount output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Math with wordcount output
# 1  
Old 07-29-2010
Math with wordcount output

Hi

I know very little about unix.
I have a unix code (which I'm running in geektools) which gives me the word count of a pages document. However, the pages document innately contains 522 words of superfluous "Ipsem Lorem..." text which are included in the count.
How would I go about subtracting 522 from the word count expressed by my code, which goes something like:

gunzip path/filename.pages | cat index.xml | xsltproc path/index.xsl | wc -w

Thank you!
# 2  
Old 07-29-2010
"grep -v " can exclude the line with "Ipsem Lorem"

Code:
grep -v "Ipsem Lorem" YOUR_FILE |wc -w

# 3  
Old 07-29-2010
lorem ipsum surely?

Anyway there appears to be a problem with your pipeline.

Quote:
gunzip path/filename.pages | cat index.xml | xsltproc path/index.xsl | wc -w
If we assume that you are processing a file called "index.xml" from the archive filename.pages, we need to remove one of the pipe characters. Then the pipeline makes sense. We can then adjust the total (assuming that the faulty pipeline was not giving you wrong figures by reading "index.xml" before gunzip finished).
My guess at the pipeline may be flawed - see below.

Code:
gunzip path/filename.pages
words_total=`cat index.xml | xsltproc path/index.xsl | wc -w`
if [ ${words_total} -ge 522 ]
then
	words_total=`expr ${words_total} - 522`
fi
echo $words_total


Afterthought: The whole script could be flawed. I am not familiar with xsltproc and its parameters and don't know if each archive includes a file called "index.xml" or where "path/index.xsl" comes from. Can you try each program in turn to be sure that the flow (particularly to pipelines) is not flawed and that the output of the pipeline is something which can be counted with "wc -w". I'm starting to wonder whether this should be a sequence of commands with no pipeline at all?

Last edited by methyl; 07-29-2010 at 08:18 AM.. Reason: Afterthought:
# 4  
Old 07-29-2010
Other then the fact that it won't update unless i change the code and change it back (still working on that) the code seems to work fine Smilie
The index.xsl is a script file i was told to download and save. Index.xml is within the .pages zip bundle. The whole thing outputs a wordcount.

Thanks for the code. After trying I realized that the wordcount was still off. I tried adding and subtract different numbers. It was a hundred too high, so I subtracted 422. Then it was about 500 to low, so I added a hundred. The numbers keep changing. It's really mysterious, but I've got the word count close enough for my purpose (that is if I can get it to update DSmilie
# 5  
Old 07-29-2010
You may find it beneficial to break the task down into separate components and then test each one individually. I experienced the variable results when trying your pipeline approach. I still wonder whether it should be a sequence of consecutive commands with the last command piped to "wc".
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Math

i have file (my_file.txt) that looks like this: 000000000000010000 000000000000010000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 all said and one, it should look... (11 Replies)
Discussion started by: lawsongeek
11 Replies

2. Programming

Math function with C

I have int miles, yards; float kilometers; float kilometers2; miles = 26; yards = 385; kilometers = 1.609 * (miles + yards / 1760.0); where int/float remains a float. How ever if I change it to kilometers = 1.609 * (miles + yards / 1760); ... (7 Replies)
Discussion started by: Fingerz
7 Replies

3. Shell Programming and Scripting

awk math and csv output

Hi I have this list 592;1;Z:\WB\DOCS;/FS3_100G/FILER112/BU/MPS/DOCS;;;;\\FILER112\BUMPS-DOCS\;580,116,544,878 Bytes;656,561 ;77,560 592;2;Z:\WB\FOCUS;/FS3_100G/FILER112/BU/MPS/FOCUS;;;;\\FILER112\BUMPS-FOCUS\;172,430 Bytes;6 ;0 ... (12 Replies)
Discussion started by: nakaedu
12 Replies

4. Shell Programming and Scripting

Need help with AWK math

I am trying to do some math, so that I can compare the average of six numbers to a variable. Here is what it looks like (note that when I divide really big numbers, it isn't a real number): $ tail -n 6 named.stats | awk -F\, '{print$1}' 1141804 1140566 1139429 1134210 1084682 895045... (3 Replies)
Discussion started by: brianjb
3 Replies

5. Shell Programming and Scripting

Help with wordcount

Hi, this is my first post so bare with me I have a file which I want to count the amounts of the same line in the file and display by using a shell script for example file1 apple apple apple. bananasi would like the output to be apple 2 apple. 1 bananas 1however, i need this... (2 Replies)
Discussion started by: legolad
2 Replies

6. Shell Programming and Scripting

math help

$ x=1 $ y=1.5 $ z=$((x*y)) bash: 1.5: syntax error: invalid arithmetic operator (error token is ".5") What's wrong? (2 Replies)
Discussion started by: rockbike
2 Replies

7. Shell Programming and Scripting

test wordcount

Hello I want to run this test: If wordcount of a command is 0 then echo XXXX else echo YYYYY if ; then echo "all devices are created on RAID10"; else echo "Some devices are created on non-RAID10"; fi I receive this message -bash: command substitution: line 1: syntax error near... (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

8. Programming

something about <math.h>

Hi, I got an easy problem for you but really difficult for me 'cause I am pretty new to this field I got header file <math.h> included in my .c file , then I write the code as below: k = sqrt(i); /* both variables k and i are int */ then I cc temp.c it says like this undefined... (4 Replies)
Discussion started by: blf0
4 Replies

9. Programming

math.h not working? o.0

Alright, umm i cant get this to work. im looking at some example and a book i have. when i try to compile my program i get an error message. ld: 0711-317 ERROR: Undefined symbol: .sqrt ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. I did #include<math.h> after my... (2 Replies)
Discussion started by: primal
2 Replies
Login or Register to Ask a Question