Du without directory and Grep for occurrences of a word

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Du without directory and Grep for occurrences of a word
# 1  
Old 04-02-2011
Du without directory and Grep for occurrences of a word

Assistance on work Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Files stored in /bin, /sbin, /usr/bin, and /usr/sbin vary in their respective sizes. In fact, there are 244 different sizes if we do not count the zero byte files. Create a command line that proves this and stores the answer, 244, in a files named sizes.txt.

On how many lines does “state” (in any case) appear in any and all of the files in /usr/dict/? Your answer should be a total, not a count per file

2. Relevant commands, code, scripts, algorithms:
See below?


3. The attempts at a solution (include all code and scripts):
  1. du -a /{,usr/}{,s}bin | sort -nu | grep -v ^0 | wc -l > ~/sizes.txt
  2. 248
I am close but i cant figure out how or why it counts the directories themselves


Code:
grep -i "state" /usr/dict/* | wc -l
-- 731
grep -i " state " /usr/dict/* | wc -l
-- 45
grep -i "\<"state"\>" /usr/dict/* | wc -l
--110

These all give me different counts...i know some are looking for just the word state and others occurrences of "state" but i when i do occurrences of "state" its not everyone of them...



4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
KeeneStateCollege(KSC), Keene(NH), USA, Charlie W., CS-215-01 Unix

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by radoulov; 04-02-2011 at 06:16 PM.. Reason: Code tags!
# 2  
Old 04-02-2011
As far as the first question is concerned:

Code:
find /{,usr/}{,s}bin -type f -exec du {} + | 
  awk 'END { 
    print c 
    }
  $1 && !_[$1]++ { 
    c++ 
    }'

With GNU awk:

Code:
find /{,usr/}{,s}bin -type f -exec du {} + | 
  awk 'END { 
    print length(_) 
    }
  $1 { _[$1] }'


Last edited by radoulov; 04-02-2011 at 06:36 PM..
This User Gave Thanks to radoulov For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to strictly grep (with before and after args) for last N number of occurrences?

Here is my grep string to print only the last occurrence, with before and after lines. Note that the tail Argument is sum of B and A args + 1, so that it prints the data of only the last 1 match. Now I need to print last 2 such matches. I thought of doubling the tail arg like 5+5+1 (For -- line),... (2 Replies)
Discussion started by: samjna
2 Replies

2. Shell Programming and Scripting

Word Occurrences script using awk

I'm putting together a script that will the count the occurrences of words in text documents. It works fine so far, but I'd like to make a couple tweaks/additions: 1) I'm having a hard time displaying the array index number, tried freq which just spit 0's back at me 2) Is there any way to... (12 Replies)
Discussion started by: ksmarine1980
12 Replies

3. UNIX for Advanced & Expert Users

Find 2 occurrences of a word and print file names

I was thinking something like this but it always gets rid of the file location. grep -roh base. | wc -l find . -type f -exec grep -o base {} \; | wc -l Would this be a job for awk? Would I need to store the file locations in an array? (3 Replies)
Discussion started by: cokedude
3 Replies

4. Shell Programming and Scripting

GREP between last occurrences of two strings

Hi I have the server.log file as: Server Stopped ABC DEF GHI JKL Server Started MNO PQR STU Server Stopped VWX YZ ABC Server Started Server Stopped 123 456 789 (9 Replies)
Discussion started by: ankur328
9 Replies

5. UNIX for Dummies Questions & Answers

BASH - Counting word occurrences in a Web Page

Hi all, I have to do a script bash (for university) that counts all word occurrences in a specific web page. anyone can help me?. Thanks :) (1 Reply)
Discussion started by: piacentero
1 Replies

6. Shell Programming and Scripting

Script to count word occurrences, but exclude some?

I am trying to count the occurrences of ALL words in a file. However, I want to exclude certain words: short words (i.e. <3 chars), and words contained in an blacklist file. There is also a desire to count words that are capitalized (e.g. proper names). I am not 100% sure where the line on... (5 Replies)
Discussion started by: Cronk
5 Replies

7. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

8. Shell Programming and Scripting

Need to find occurrences of email domains in all files in a directory

Hello Everyone! I trust you are off to a great week! Trying to output the name and count of each uniquely occurring domain in the current directory for a portion of a script I'm building. Here's what I'm stuck on: - Need to find UNIQUE occurences of domains (*@domain.com) in ALL files in... (4 Replies)
Discussion started by: linuxhombre
4 Replies

9. Shell Programming and Scripting

Count the number of occurrences of the word

I am a newbie in UNIX shell script and seeking help on this UNIX function. Please give me a hand. Thanks. I have a large file. Named as 'MyFile'. It was tab-delmited. I am told to write a shell function that counts the number of occurrences of the ord “mysring” in the file 'MyFile'. (1 Reply)
Discussion started by: duke0001
1 Replies

10. UNIX for Dummies Questions & Answers

grep unique occurrences

Hi, How do i grep unique occurrences from a file. I have a log file with multiple occurrences of 'foo' for instance. When i do: grep foo, I get all the lines that contain foo. Is there any way to get only one line for foo? Example file: foo at 09.01am Fri 11 May 2007 foo at 09.13am... (6 Replies)
Discussion started by: mz043
6 Replies
Login or Register to Ask a Question