Help in writing script

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'.

  1. I open a subshell (...) so I am not changing the $PWD of the caller when I cd.
  2. I put those two parameters into variables.
  3. I list all the c files, newest first,
  4. into sed, which substitutes for beginning of line ^ not-space [^ ] any number of times * one space (5 times) then capturing \(..\) up to the last space as one field (the time part, but this does not work well for ls -l on sym links, just simple files) and everything else (the file name) as the second field. Sed throws away the first 5 fields (not captured), rewrites the two fields into an echo command with an embedded grep -c to count the references, a tab to accommodate varying number width from grep -c, and the captured fields.
  5. sed quits after converting 20 lines.
  6. The dynamically created script goes into ksh.
 
(
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!!! :b: