Hi,
I need to find all files of particular day lets say for 2nd august in below.
-rw-r--r-- 1 skl eusdc 8168 Aug 5 19:31 aabc123.txt
-rw-r--r-- 1 skl eusdc 4251 Aug 5 19:31 aabc124.txt
-rw-r--r-- 1 skl eusdc 4252 Aug 6 19:31 aabc125.txt
-rw-r--r-- 1 skl eusdc 3895 Aug 6 19:31 aabc213.txt
-rw-r--r-- 1 skl eusdc 3896 Aug 2 19:31 aabc456.txt
-rw-r--r-- 1 skl eusdc 3183 Aug 2 19:31 aabc63453.txt
-rw-r--r-- 1 skl eusdc 3184 Aug 2 19:31 aabcqwe.txt
-rw-r--r-- 1 skl eusdc 1047 Aug 3 07:30 mnbvcc.txt
-rw-r--r-- 1 skl eusdc 1048 Aug 3 07:30 as54633.txt
-rw-r--r-- 1 skl eusdc 1047 Aug 3 07:30 poiuy78.txt
-rw-r--r-- 1 skl eusdc 1048 Aug 3 07:30 sdfsd.doc
-rw-r--r-- 1 skl eusdc 10596 Aug 3 07:30 dfgd.txt
-rw-r--r-- 1 skl eusdc 10600 Aug 3 07:30 qweqw.doc
i need to find all files of lets say Aug 2 and the counts for a particular string lets say "abc" is present in the files received for Aug 2
How about:
ls -ld *abc* | grep "Aug 2"
It just give me files of Aug 3. How about finding the total count of a string lets say "sachin" in all the files of Aug 3
agn
August 4, 2010, 12:56am
6
Try
$ ls -l | awk '/Aug 2/ { print $NF }' | grep -c 'sachin'
It still does not answer my question. It looks for string 'sachin' in the filenames which is i dont want. I need to find total count of string 'sachin' in the text present inside the files not in the filenames.
agn
August 4, 2010, 2:27am
8
$ ls -l | awk '/Aug 2/ { print $NF }' | xargs grep -c 'sachin'
Or
$ for f in $(ls -l | awk '/Aug 2/ { print $NF }'); do grep -c 'sachin' $f; done
OR
grep "sachin" `ls -ltr | grep " Aug 2 " | awk '{print $9}'`
ls -l | awk '/Aug 2/ { print $NF }' | xargs grep -c 'sachin' | awk -F ":" '{ total += $2 } END {print total}';
Hi Pravin..
I tried what u said but it gives me the below error:
awk: syntax error near line 1
awk: bailing out near line 1
$ xargs: Child killed with signal 13
It's running fine for me. You can try another one.
total=0;for f in $(ls -l | awk '/Jun 22/ { print $NF }'); do cnt=`grep -c 'pravin' $f` total=`expr $cnt + $total`;done ; echo $total
methyl
August 4, 2010, 6:32am
14
If you are on Solaris, try "nawk" not "awk".
Pls try this..
ls -l | grep "Aug 2" | awk '{print $8}' | xargs -iVAR grep -i sachin VAR | wc -l
1 Like
This is the perfect answer that i was looking for. Great job Rajamadhavan:b: