i need some help in donig some actions on files in a library.
i want to get the n last files, and print to the screen their name, date, and how many times a specific string appears in each file..
how can i do this..?...
i need some help in donig some actions on files in a library.
i want to get the n last files, and print to the screen their name, date, and how many times a specific string appears in each file..
how can i do this..?...
How many total files? Something like "ls -lt <list>" has limits on most systems. Once you have the file names and dates, grep -c counts lines with pattern.
Try this one:
ls | tail -5 > /tmp/tot.txt
astring=ball
for i in `cat /tmp/tot.txt`
do
a=`cat $i | grep $astring | wc -l`
echo " There are $a $astring in the file $i"
done
Narrative: Suppose I am searching for 'printf(' family calls in my C source directory 'mysrc'.
(
export astring="printf(" lib_dir=mysrc
cd $lib_dir
ls -lt *.c | sed '
s/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *\(.*\) \(.*\)/echo $( grep -c "'"$astring"'" <\2 )" \1 \2"/
20q
' | ksh
)
1 Nov 18 17:20 pctbin.c
4 Nov 12 12:13 xdemux.c
2 Nov 12 11:32 fgets_eof.c
0 Nov 10 16:58 cps.c
0 Nov 3 09:30 tps.c
0 Nov 3 09:14 tcs.c
0 Oct 28 14:24 usleep2.c
0 Oct 18 11:03 allwait.c
1 Oct 15 16:58 fwcl.c
4 Oct 14 14:25 fxargs2.c
10 Oct 14 12:20 tm2tm.c
12 Oct 14 10:35 autotab.c
5 Jul 23 15:25 undelim.c
0 Jun 15 12:36 lineso2.c
0 Jun 15 11:03 lineso.c
2 Jun 3 10:52 realpath.c
0 May 28 10:28 pt2h.c
0 May 25 08:57 ghead.c
32 May 25 08:54 string_functions.c
1 May 25 08:54 psal.c
first of all thank you very much for the help...
second, DGPickett, if you can explain me the commands you write it will be great...
Sure, see above.
thank you very much!!!