removing part of a file

Right this is quite a long one,
I have a script which complies all listed stats files into one file and emails it out,
However this has to be run manually and i would like it to run automatically,

I have a list of files eg

sa17
sa18
sa19
sa20
sa21
 

one file for each of last weeks working days,
howver I need them in this format

17 18 19 20 21

And then I need to use them as the input to a script.
any info is helpful

much info on this would be appreciated.

ls sa* | sed 's/[a-z]*//g' will give you the list of files with "sa" removed.

Try like..

ls sa*.txt|awk '{print substr($1,3)}'|sed  's/.txt//g' 

---------- Post updated at 06:37 AM ---------- Previous update was at 06:32 AM ----------

Try like...

ls sa*.txt|awk '{print substr($1,3)}'|sed  's/.txt//g' |tr '\n' " " <   

Like this?

$ ls
sa17  sa18  sa19  sa20  sa21
$ ls|while read f;do echo mv $f ${f#??} && echo 'MYSCRIPT' ${f#??};done
mv sa17 17
MYSCRIPT 17
mv sa18 18
MYSCRIPT 18
mv sa19 19
MYSCRIPT 19
mv sa20 20
MYSCRIPT 20
mv sa21 21
MYSCRIPT 21

Remove the echo's if you are happy. :slight_smile:

Sorry, if I was to remove the echo's and want to run my script which is called sar.sh what should it look like?

ls|while read f;do mv $f ${f#??} && sar.sh ${f#??};done

right Im thinking an easier way is run a find to get all the sa files written last week and then I want to run my sar.sh script on each of these. so at the momment i have

find /var/adm/sa -type f -mtime +2 | grep sa[1-9] | while read f;do sar.sh ;done

is this ok as at the minute it doesnt seem to be working

Well, as we don't have an idea how your directory structure looks like, we can't tell how many files will be found below that starting dir. You may want to add the -prune action. Also, the -mtime +2 (older than now - (48h+)) is depending on the time you issue the command; it will yield different results on Monday or on Tuesday, and if issued at 10:00h in the morning or later at night.
The grep will grep filenames sa1 till sa9, but not sa10, sa15, or sa17. Use [1-9][1-9] for a two digit wildcard.
And, finally, you read filenames in the while loop, but you don't use them as a parameter for your sar.sh script; unless you are using the f variable in the script, all the filename a thrown to the bin, making the earlier commands redundant.

I have sorted this out using the -exec function of the find command,
I needed to run the sar -uf command on each individual file in the /var/adm/sa directory

and using grep sa[1-9] does grep for two digits or more as the [1-9] for grep is a wildcard for all numbers not just the ones listed

Sorry for my sloppy wording; you are right, it will grep sa17, but it will grep sa1A as well, should it exist.