count and awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting count and awk
# 1  
Old 11-28-2009
count and awk

Hi my task is to show the percentage of files accessed in /home in one week.

I have got as far as displying the files, kind of. I am not sure how to format them into a list. I've tried using awk but hasn't worked yet.
any help would be fantastic.

this is what i have got so far

Code:
echo "The files accessed in /home in the past 7 days are: " 
 `find ~ -daystart -atime -7 -mtime -7`

the result ends up like this
Code:
/home/jsk1gcc/gensysinfo /home/jsk1gcc/netinfo /home/jsk1gcc/testwork /home/jsk1gcc/.bash_history /home/jsk1gcc/hardutilinfo /home/jsk1gcc/.viminfo /home/jsk1gcc/userinfo /home/jsk1gcc/fileman

I would like to know how to list them, Normally I would use awk and print $, But with the outcome changing every time how do I do it?

One other question is how do i count them?, again I can do it when they remain static using

Code:
`ls -l | grep -c "^-.*"`


Pusdo code.
count all files in the dir
say this is how many files are in a dir in %
say these are the files that have accessed


I'm sorry is using pusdo code is against the rules of the forum, I didn't know how else to explain what i needed to know.

Thanks is advance.
Jade.
# 2  
Old 11-28-2009
Something like this?

Code:
find ~ -type f -daystart -atime -7 -mtime -7 | awk 'END{print "total: "NR}1'

# 3  
Old 11-28-2009
Yeah that does work thankyou. I get the total of the files.

Though I still have the problem with the output of the files. How do I list them

something like
Code:
grep /home | awk '{print $1,$2,$3}'

nb: tried above code and does not work

The whole section of code looks like this.
Code:
 
echo "The number of files in current directory are: " ls -l | grep -c "^-.*"
echo      
echo "The files accessed in /home in the past 7 days are: "  `find ~ -daystart -atime -7 -mtime -7  \! -type d | grep /home | awk '{print $1,$2,$3}'| awk
 'END{print "\ntotal: "NR}1'`
echo
echo "Hit the Enter key to continue"
read junk;;

I understand that it is a bit messy atm and that I have repeated myself a little. bah! noggin turning to mush right now. =)


Thanks.
Jade.

---------- Post updated at 07:21 PM ---------- Previous update was at 07:19 PM ----------

forgot to put in error msg.

Code:
./fileman: line 21: The number of files in current directory are: : command not found
0

The files accessed in /home in the past 7 days are:  /home/jsk1gcc/procinfo /home/jsk1gcc/script /home/jsk1gcc/.fileman.swp /home/jsk1gcc/.hardutilinfo.swp /home/jsk1gcc/gensysinfo /home/jsk1gcc/tempasswd /home/jsk1gcc/netinfo /home/jsk1gcc/.bash_history /home/jsk1gcc/hardutilinfo /home/jsk1gcc/.viminfo /home/jsk1gcc/userinfo /home/jsk1gcc/fileman /home/jsk1gcc/.userinfo.swp total: 13

Hit the Enter key to continue

Jade.
# 4  
Old 11-29-2009
Should be something like:

Code:
echo "The number of files in current directory are: "
ls -l | grep -c "^-.*"
echo
echo -n "The files accessed in /home in the past 7 days are: "
find ~ -type f -daystart -atime -7 -mtime -7 | awk 'END{print "total: "NR}'
echo
echo "Hit the Enter key to continue"
read junk


Last edited by Franklin52; 11-29-2009 at 08:20 AM.. Reason: splitting the ls command
# 5  
Old 11-29-2009
Computer Thanks

Thankyou, OMG thankyou so much, that was doing my head in.
something so simple.

I was working on it for about 8 hours, after that amount of time, I can't see the soultions anymore.
Thankyou.

Jade.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Category and count with awk

I want to categorize and count the as below: Input file: A1 G1 C1 F1 A2 G1 C1 F1 A3 G1 C1 F2 A4 G1 C2 F2 A7 G1 C2 F2 A8 G1 C2 F3 A11 G1 C2 F3 A23 G1 C2 F3 B4 G1 C2 F3 AC4 G2 C3 F4 B6 G2 C4 F4 BB5 G2 C4 F4 A25 G2 C5 F4 B13 G2 C5 F5 D12 G2 C5 F5 D2 G2 C5 F5 (3 Replies)
Discussion started by: aydj
3 Replies

2. Shell Programming and Scripting

awk to count using each unique value

Im looking for an awk script that will take the unique values in column 5, then print and count the unique values in column 6. CA001011500 11111 11111 -9999 201301 AAA CA001012040 11111 11111 -9999 201301 AAA CA001012573 11111 11111 -9999 201301 BBB CA001012710 11111 11111 -9999 201301... (4 Replies)
Discussion started by: ncwxpanther
4 Replies

3. Shell Programming and Scripting

How to count a number using awk?

hi, does any one know how to compare a file1 with many files and have to count a number (i.e. 1) like the following ..Thanx in advance input file1 file2 file3 filen 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 output instances in file1 only - 2 instances in... (3 Replies)
Discussion started by: quincyjones
3 Replies

4. Shell Programming and Scripting

Awk: Print count for column in a file using awk

Hi, I have the following input in a file & need output as mentioned below(need counter of every occurance of field which is to be increased by 1). Input: 919143110065 919143110065 919143110052 918648846132 919143110012 918648873782 919143110152 919143110152 919143110152... (2 Replies)
Discussion started by: siramitsharma
2 Replies

5. Shell Programming and Scripting

awk - count character count of fields

Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies

6. Shell Programming and Scripting

awk and count sum ?

I have a input.txt file which have 3 fields separate by a comma place, os and timediff in seconds tampa,win7, 2575 tampa,win7, 157619 tampa,win7, 3352 dallas,vista,604799 greenbay,winxp, 14400 greenbay,win7 , 518400 san jose,winxp, 228121 san jose,winxp, 70853 san jose,winxp, 193514... (5 Replies)
Discussion started by: sabercats
5 Replies

7. UNIX for Dummies Questions & Answers

AWK-COUNT

Hi , HOW DO I COUNT THE NO of fields in a particular line of a file using awk EX: If file name is Pravee a|2|3|4|y the command shid display the result as 4 Please advise (2 Replies)
Discussion started by: praviper
2 Replies

8. Shell Programming and Scripting

Sort and count using AWK

Hi, I've a fixed width file where I need to count the number of patterns from each line between characters 1 to 15 . so can we sort them and get a count for each pattern on the file between 1 to 15 characters. 65795648617522383763831552 410828003265795648 6175223837... (5 Replies)
Discussion started by: rudoraj
5 Replies

9. Shell Programming and Scripting

count the max by awk

hey everybody .. I have a problem when I use this command to count the Max number by awk it give to me 99 while there are numbers bigger than 99 awk 'NR==0 { temp = $0 ;next} { if ( $0 >= temp ) { temp=$0 } } END{ print "Maximum Number:"temp""}' file thank you for your help... (9 Replies)
Discussion started by: halola85
9 Replies

10. Shell Programming and Scripting

to count their numbers using awk

suppose u have a file AAG AAG GYG HYH GTG AAG AAG HYH GYG HUH JUJ JUJ AAG so output shud have AAG = 5 GYG=2 HYH=2 HUH=1JUJ=2 (3 Replies)
Discussion started by: cdfd123
3 Replies
Login or Register to Ask a Question