![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to add numbers | email-lalit | Shell Programming and Scripting | 8 | 05-12-2008 06:34 PM |
| need top 3 numbers | shary | Shell Programming and Scripting | 4 | 03-25-2008 01:58 AM |
| ksh and hex numbers | JamesByars | Shell Programming and Scripting | 2 | 01-15-2008 03:36 PM |
| to count their numbers using awk | cdfd123 | Shell Programming and Scripting | 3 | 10-15-2007 03:24 AM |
| Add some numbers! | TalkShowHost | Shell Programming and Scripting | 3 | 05-15-2002 12:28 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
I have plain text file "tmp" which include a range of numbers(bytes), say like: Code:
123 234 567 2434 2323 213123 should I use AWK, then how? I am a newer in Bourne shell, please give me a hand, thanks a lot |
|
|||||
|
Without the need to sound rude or presumptuous, but this could be seen as a homework type question - which is a no-no. Please refer to this thread.
If you post what you've been able to do so far (by means of script/etc); in attempting to solve your own problem - then we can better direct/assist you. |
|
||||
|
Hi, Actually, that is a question from my study, but I just ask for a point which I can not handle, I never ask somebody to do my whole job!
What I do so far, I need to sort a range of log file, and caculate the most requested files, total byte transferred and how much percent files has been successfully access. Now I have used AWK to cut the log file off, and put all the requested number into a tmperory file, now Just don't know any function or comand to use to add all the number together to get the sum, so could anybody to give me a hand. Thanks |
|
||||
|
Awk is also a natural choice to do this sort of job.
awk 'BEGIN{total=0} {total += $1} END{print total}' tmp Use something like the above but before implementing it into your script get a good understanding of what it does and how it works. That is the only way you will be able to do it on your own next time. Matt. |
|
||||
Hi, thanx very much, butterfm and perdo! Your suggestions are extremelly useful, now I can display the total number of byte like something below: Code:
total_byte()
{
awk '{print $10}' access.log.1 | sort -k 1 | sort -o /tmp/pxi_tmp1
sum=`awk 'BEGIN{total=0}{total += $1} END{print total}' /tmp/pxi_tmp1`
echo "Total byte transmitted: $sum"
}
if [ $2 = -N ]; then
echo "Here are $3 most popular files:"
awk '{print $7}' access.log.1 | sort -k 1 | uniq -c | sort -ur -o /tmp/pxi_tmp
head -${3:-10} /tmp/pxi_tmp
total_byte
total_request
rm /tmp/pxi_tmp
.I just have another point which confused me all the time, say if I want to display the files in my tmp file exclude those .gif, .jpg, .jpeg and .png Code:
162 /index.html 129 /title.gif 22 /~bob/ 483 /~fred/index.html 13 /~fred/links.gif 11 /~fred/blog.jpg I would like to display like belows: Code:
162 /index.html 22 /~bob/ 483 /~fred/index.html Code:
elif [ $2 = -I ]; then
echo "Here are numbers of moset requested files you want:"
awk '{print $7}' access.log.1 | sort -k 1 | uniq -c | sort -ur -o /tmp/pxi_tmp
${/tmp/tmp.txt##/*/} >> /tmp/pxi_tmp1
head -n 10 /tmp/pxi_tmp1
total_byte
total_request
rm /tmp/pxi_tmp1
rm /tmp/pxi_tmp
![]() |
|
||||
|
Hi pnxi,
Again using AWK, this will ignore jpg and gif files. You will need to add jpeg and png files. awk '! ($2 ~ /jpg/ || $2 ~ /gif/) {print $0}' tmp It's worth taking the time to learn awk if you can. It is extremely powerful, particularly for the sort of thing that you are trying to do. grep could also be used to do the job. grep -v "[jg][pi][gf]" tmp Matt. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|