Computing.Net > Forums > Unix > word count

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

word count

Reply to Message Icon

Name: karl1
Date: December 20, 2006 at 06:09:42 Pacific
OS: cygwin
CPU/Ram: 1
Product: 12
Comment:

hey,
could some1 help me with this?
i am trying to get a word count of lines between lines starting with a letter. the file is like this:

AUS_LO
109D
265C
AUS_HO
1078D
1093C
AUS_PO

so a count of lines from AUS_LO to AUS_HO and count between AUS_HO and AUS_PO.

any help would be really apreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: December 20, 2006 at 09:39:09 Pacific
Reply:

# should be 4
sed -n "/AUS_LO/,/AUS_HO/p" data.file|wc -w

# should be 7
sed -n "/AUS_LO/,/AUS_PO/p" data.file|wc -w


0

Response Number 2
Name: karl1
Date: December 21, 2006 at 06:42:18 Pacific
Reply:

thanks for replying,
the names aus_lo and aus_po change all the time, wat the file is is a list of changes between two folders and the numbers are the line number of the changes.
is there anyway to say find numbers between letters? like
sed -n "/[a-z]/,/[a-z]/p" data.file|wc -w


0

Response Number 3
Name: nails
Date: December 21, 2006 at 09:39:01 Pacific
Reply:

I'm not understanding your question, but it looks like you want to do more processing on data found within a range. sed doesn't do if comparisons well. awk also supports range patterns. The sed example could be rewritten this way:

awk '$1 ~ /AUS_LO/ , $1 ~ /AUS_HO/' data.file|wc -w

If you wanted to act on each line within the range, you could do something like this:

awk '$1 ~ /AUS_LO/ , $1 ~ /AUS_HO/
{
print "do something"
} ' data.file



0

Response Number 4
Name: karl1
Date: December 22, 2006 at 00:52:27 Pacific
Reply:

the file is a list of changes in files, a diff is used to check between 2 folders, the results come back word /numbers/ word e.g.
aus
123c1
546d1
bel
123c1
che
123c2

was wondering is there any way to get the amount of changes between the first word and the second so the output would be

aus
2
bel
1
che
1


0

Response Number 5
Name: nails
Date: December 22, 2006 at 09:25:37 Pacific
Reply:

Assuming that if the first character is alpha it's a file name and if the first character is integer, it's a change, you can set up a break point report using awk - nawk in my case since I'm using Solaris:

#!/bin/ksh

nawk ' BEGIN { cnter=0 }
{
if ($0 ~ /^[a-zA-Z]+/)
{
# print the number of changes if past first line
if (NR > 1)
{
print cnter
cnter=0
}

print $0
continue
}

if ($0 ~ /^[1-9]+/)
cnter++

} END { print cnter } ' datafile.txt
# end script

I also assume the file ends with a change


0

Related Posts

See More



Response Number 6
Name: karl1
Date: January 2, 2007 at 01:25:22 Pacific
Reply:

thats brill, works very well, thanks for your help


0

Sponsored Link
Ads by Google
Reply to Message Icon

shell script Remotely Removing a File



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: word count

Word count in unix www.computing.net/answers/unix/word-count-in-unix/7143.html

script with word count compare www.computing.net/answers/unix/script-with-word-count-compare/3700.html

Count no. of words of variable www.computing.net/answers/unix/count-no-of-words-of-variable/5233.html